vortex_array/arrays/primitive/vtable/
array.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::hash::Hash;
5use std::hash::Hasher;
6
7use vortex_dtype::DType;
8
9use crate::Precision;
10use crate::arrays::PrimitiveArray;
11use crate::arrays::PrimitiveVTable;
12use crate::hash::ArrayEq;
13use crate::hash::ArrayHash;
14use crate::stats::StatsSetRef;
15use crate::vtable::BaseArrayVTable;
16
17impl BaseArrayVTable<PrimitiveVTable> for PrimitiveVTable {
18    fn len(array: &PrimitiveArray) -> usize {
19        array.byte_buffer().len() / array.ptype().byte_width()
20    }
21
22    fn dtype(array: &PrimitiveArray) -> &DType {
23        &array.dtype
24    }
25
26    fn stats(array: &PrimitiveArray) -> StatsSetRef<'_> {
27        array.stats_set.to_ref(array.as_ref())
28    }
29
30    fn array_hash<H: Hasher>(array: &PrimitiveArray, state: &mut H, precision: Precision) {
31        array.dtype.hash(state);
32        array.buffer.array_hash(state, precision);
33        array.validity.array_hash(state, precision);
34    }
35
36    fn array_eq(array: &PrimitiveArray, other: &PrimitiveArray, precision: Precision) -> bool {
37        array.dtype == other.dtype
38            && array.buffer.array_eq(&other.buffer, precision)
39            && array.validity.array_eq(&other.validity, precision)
40    }
41}