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

Function normalize_coord

nodedb-array/src/coord/normalize.rs:35–52  ·  view source on GitHub ↗

Normalize one cell coordinate into per-dim integer coordinates in `[0, 2^bits)`. The output `Vec` has the same arity as the schema.

(
    schema: &ArraySchema,
    components: &[CoordValue],
    bits: u32,
)

Source from the content-addressed store, hash-verified

33/// Normalize one cell coordinate into per-dim integer coordinates in
34/// `[0, 2^bits)`. The output `Vec` has the same arity as the schema.
35pub fn normalize_coord(
36 schema: &ArraySchema,
37 components: &[CoordValue],
38 bits: u32,
39) -> ArrayResult<Vec<u64>> {
40 if components.len() != schema.arity() {
41 return Err(ArrayError::CoordArityMismatch {
42 array: schema.name.clone(),
43 expected: schema.arity(),
44 got: components.len(),
45 });
46 }
47 let mut out = Vec::with_capacity(components.len());
48 for (dim, value) in schema.dims.iter().zip(components.iter()) {
49 out.push(normalize_one(&schema.name, dim, value, bits)?);
50 }
51 Ok(out)
52}
53
54fn normalize_one(array: &str, dim: &DimSpec, value: &CoordValue, bits: u32) -> ArrayResult<u64> {
55 let max = if bits >= 64 {

Calls 6

normalize_oneFunction · 0.85
lenMethod · 0.45
arityMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45