vortex_array/arrays/varbinview/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::varbinview::{VarBinViewArray, VarBinViewVTable};
10use crate::hash::{ArrayEq, ArrayHash};
11use crate::stats::StatsSetRef;
12use crate::vtable::ArrayVTable;
13
14impl ArrayVTable<VarBinViewVTable> for VarBinViewVTable {
15    fn len(array: &VarBinViewArray) -> usize {
16        array.views.len()
17    }
18
19    fn dtype(array: &VarBinViewArray) -> &DType {
20        &array.dtype
21    }
22
23    fn stats(array: &VarBinViewArray) -> StatsSetRef<'_> {
24        array.stats_set.to_ref(array.as_ref())
25    }
26
27    fn array_hash<H: std::hash::Hasher>(
28        array: &VarBinViewArray,
29        state: &mut H,
30        precision: Precision,
31    ) {
32        array.dtype.hash(state);
33        for buffer in array.buffers.iter() {
34            buffer.array_hash(state, precision);
35        }
36        array.views.array_hash(state, precision);
37        array.validity.array_hash(state, precision);
38    }
39
40    fn array_eq(array: &VarBinViewArray, other: &VarBinViewArray, precision: Precision) -> bool {
41        array.dtype == other.dtype
42            && array.buffers.len() == other.buffers.len()
43            && array
44                .buffers
45                .iter()
46                .zip(other.buffers.iter())
47                .all(|(a, b)| a.array_eq(b, precision))
48            && array.views.array_eq(&other.views, precision)
49            && array.validity.array_eq(&other.validity, precision)
50    }
51}