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