Skip to main content

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