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

Function normalize_one

nodedb-array/src/coord/normalize.rs:54–86  ·  view source on GitHub ↗
(array: &str, dim: &DimSpec, value: &CoordValue, bits: u32)

Source from the content-addressed store, hash-verified

52}
53
54fn normalize_one(array: &str, dim: &DimSpec, value: &CoordValue, bits: u32) -> ArrayResult<u64> {
55 let max = if bits >= 64 {
56 u64::MAX
57 } else {
58 (1u64 << bits) - 1
59 };
60 match (&dim.dtype, value, &dim.domain.lo, &dim.domain.hi) {
61 (DimType::Int64, CoordValue::Int64(v), DomainBound::Int64(lo), DomainBound::Int64(hi))
62 | (
63 DimType::TimestampMs,
64 CoordValue::TimestampMs(v),
65 DomainBound::TimestampMs(lo),
66 DomainBound::TimestampMs(hi),
67 ) => map_int(array, dim, *v, *lo, *hi, max),
68 (
69 DimType::Float64,
70 CoordValue::Float64(v),
71 DomainBound::Float64(lo),
72 DomainBound::Float64(hi),
73 ) => map_float(array, dim, *v, *lo, *hi, max),
74 (
75 DimType::String,
76 CoordValue::String(v),
77 DomainBound::String(_),
78 DomainBound::String(_),
79 ) => Ok(map_string(v, max)),
80 _ => Err(ArrayError::CoordOutOfDomain {
81 array: array.to_string(),
82 dim: dim.name.clone(),
83 detail: "coord variant does not match dim dtype".to_string(),
84 }),
85 }
86}
87
88fn map_int(array: &str, dim: &DimSpec, v: i64, lo: i64, hi: i64, max: u64) -> ArrayResult<u64> {
89 if v < lo || v > hi {

Callers 1

normalize_coordFunction · 0.85

Calls 5

map_intFunction · 0.85
map_floatFunction · 0.85
map_stringFunction · 0.85
to_stringMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected