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

Function decode

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

Inverse of [`encode`].

(idx: u64, n: usize, bits: u32)

Source from the content-addressed store, hash-verified

26
27/// Inverse of [`encode`].
28pub fn decode(idx: u64, n: usize, bits: u32) -> ArrayResult<Vec<u64>> {
29 check_shape(n, bits)?;
30 let mut out = vec![0u64; n];
31 for b in (0..bits).rev() {
32 for (i, slot) in out.iter_mut().enumerate().take(n) {
33 let shift = b * n as u32 + (n as u32 - 1 - i as u32);
34 let bit = (idx >> shift) & 1;
35 *slot = (*slot << 1) | bit;
36 }
37 }
38 Ok(out)
39}
40
41fn check_shape(n: usize, bits: u32) -> ArrayResult<()> {
42 if n > MAX_DIMS {

Callers 15

decode_hilbert_prefixFunction · 0.70
decode_zorder_prefixFunction · 0.70
openMethod · 0.50
read_tileMethod · 0.50
open_with_kekMethod · 0.50
header_round_tripFunction · 0.50
framing_round_tripFunction · 0.50

Calls 3

iter_mutMethod · 0.80
check_shapeFunction · 0.70
takeMethod · 0.45