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