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