Skip to main content

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