Skip to main content

vortex_array/arrays/decimal/vtable/
array.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::hash::Hash;
5
6use crate::Precision;
7use crate::arrays::DecimalArray;
8use crate::arrays::DecimalVTable;
9use crate::dtype::DType;
10use crate::dtype::DecimalType;
11use crate::hash::ArrayEq;
12use crate::hash::ArrayHash;
13use crate::stats::StatsSetRef;
14use crate::vtable::BaseArrayVTable;
15
16impl BaseArrayVTable<DecimalVTable> for DecimalVTable {
17    fn len(array: &DecimalArray) -> usize {
18        let divisor = match array.values_type {
19            DecimalType::I8 => 1,
20            DecimalType::I16 => 2,
21            DecimalType::I32 => 4,
22            DecimalType::I64 => 8,
23            DecimalType::I128 => 16,
24            DecimalType::I256 => 32,
25        };
26        array.values.len() / divisor
27    }
28
29    fn dtype(array: &DecimalArray) -> &DType {
30        &array.dtype
31    }
32
33    fn stats(array: &DecimalArray) -> StatsSetRef<'_> {
34        array.stats_set.to_ref(array.as_ref())
35    }
36
37    fn array_hash<H: std::hash::Hasher>(array: &DecimalArray, state: &mut H, precision: Precision) {
38        array.dtype.hash(state);
39        array.values.array_hash(state, precision);
40        std::mem::discriminant(&array.values_type).hash(state);
41        array.validity.array_hash(state, precision);
42    }
43
44    fn array_eq(array: &DecimalArray, other: &DecimalArray, precision: Precision) -> bool {
45        array.dtype == other.dtype
46            && array.values.array_eq(&other.values, precision)
47            && array.values_type == other.values_type
48            && array.validity.array_eq(&other.validity, precision)
49    }
50}