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