MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encode

Function encode

nodedb-array/src/coord/zorder.rs:14–25  ·  view source on GitHub ↗

Interleave per-dim bits into a single Z-order index, MSB first.

(coords: &[u64], bits: u32)

Source from the content-addressed store, hash-verified

12
13/// Interleave per-dim bits into a single Z-order index, MSB first.
14pub fn encode(coords: &[u64], bits: u32) -> ArrayResult<u64> {
15 check_shape(coords.len(), bits)?;
16 let n = coords.len();
17 let mut idx: u64 = 0;
18 for b in (0..bits).rev() {
19 for c in coords.iter().take(n) {
20 let bit = (*c >> b) & 1;
21 idx = (idx << 1) | bit;
22 }
23 }
24 Ok(idx)
25}
26
27/// Inverse of [`encode`].
28pub fn decode(idx: u64, n: usize, bits: u32) -> ArrayResult<Vec<u64>> {

Callers 15

encode_hilbert_prefixFunction · 0.70
encode_zorder_prefixFunction · 0.70
zorder_round_trip_2dFunction · 0.70
zorder_round_trip_3dFunction · 0.70
append_framedMethod · 0.50
framing_round_tripFunction · 0.50
framing_round_trip_emptyFunction · 0.50

Calls 4

check_shapeFunction · 0.70
lenMethod · 0.45
takeMethod · 0.45
iterMethod · 0.45

Tested by 8

zorder_round_trip_2dFunction · 0.56
zorder_round_trip_3dFunction · 0.56
framing_round_tripFunction · 0.40
framing_round_trip_emptyFunction · 0.40