Skip to main content

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