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