Skip to main content

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