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