Skip to main content

vortex_array/arrays/scalar_fn/vtable/
array.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::hash::Hash;
5use std::hash::Hasher;
6
7use crate::ArrayEq;
8use crate::ArrayHash;
9use crate::Precision;
10use crate::arrays::scalar_fn::array::ScalarFnArray;
11use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
12use crate::dtype::DType;
13use crate::stats::StatsSetRef;
14use crate::vtable::BaseArrayVTable;
15
16impl BaseArrayVTable<ScalarFnVTable> for ScalarFnVTable {
17    fn len(array: &ScalarFnArray) -> usize {
18        array.len
19    }
20
21    fn dtype(array: &ScalarFnArray) -> &DType {
22        &array.dtype
23    }
24
25    fn stats(array: &ScalarFnArray) -> StatsSetRef<'_> {
26        array.stats.to_ref(array.as_ref())
27    }
28
29    fn array_hash<H: Hasher>(array: &ScalarFnArray, state: &mut H, precision: Precision) {
30        array.len.hash(state);
31        array.dtype.hash(state);
32        array.scalar_fn.hash(state);
33        for child in &array.children {
34            child.array_hash(state, precision);
35        }
36    }
37
38    fn array_eq(array: &ScalarFnArray, other: &ScalarFnArray, precision: Precision) -> bool {
39        if array.len != other.len {
40            return false;
41        }
42        if array.dtype != other.dtype {
43            return false;
44        }
45        if array.scalar_fn != other.scalar_fn {
46            return false;
47        }
48        for (child, other_child) in array.children.iter().zip(other.children.iter()) {
49            if !child.array_eq(other_child, precision) {
50                return false;
51            }
52        }
53        true
54    }
55}