Skip to main content

nodedb_array/coord/
decode.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! High-level prefix decoding.
4//!
5//! Decoding is informational — recovers per-dim integer coordinates
6//! from a prefix. Inverse normalization (back into typed
7//! [`crate::types::CoordValue`]) is intentionally not provided: the
8//! prefix is lossy for `Float64` and `String` dims by design.
9
10use super::{hilbert, zorder};
11use crate::error::ArrayResult;
12
13pub fn decode_hilbert_prefix(idx: u64, n_dims: usize, bits: u32) -> ArrayResult<Vec<u64>> {
14    hilbert::decode(idx, n_dims, bits)
15}
16
17pub fn decode_zorder_prefix(idx: u64, n_dims: usize, bits: u32) -> ArrayResult<Vec<u64>> {
18    zorder::decode(idx, n_dims, bits)
19}
20
21#[cfg(test)]
22mod tests {
23    use super::super::{hilbert, zorder};
24    use super::*;
25
26    #[test]
27    fn hilbert_decode_matches_module() {
28        let idx = hilbert::encode(&[3, 5], 4).unwrap();
29        assert_eq!(decode_hilbert_prefix(idx, 2, 4).unwrap(), vec![3, 5]);
30    }
31
32    #[test]
33    fn zorder_decode_matches_module() {
34        let idx = zorder::encode(&[3, 5], 4).unwrap();
35        assert_eq!(decode_zorder_prefix(idx, 2, 4).unwrap(), vec![3, 5]);
36    }
37}