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