Skip to main content

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