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,
)
| 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. |
| 35 | pub 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 | |
| 54 | fn normalize_one(array: &str, dim: &DimSpec, value: &CoordValue, bits: u32) -> ArrayResult<u64> { |
| 55 | let max = if bits >= 64 { |