vortex_array/arrays/varbin/compute/
is_constant.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::accessor::ArrayAccessor;
7use crate::arrays::{VarBinArray, VarBinVTable};
8use crate::compute::{IsConstantKernel, IsConstantKernelAdapter, IsConstantOpts};
9use crate::register_kernel;
10
11impl IsConstantKernel for VarBinVTable {
12    fn is_constant(
13        &self,
14        array: &VarBinArray,
15        opts: &IsConstantOpts,
16    ) -> VortexResult<Option<bool>> {
17        if opts.is_negligible_cost() {
18            return Ok(None);
19        }
20        array.with_iterator(compute_is_constant).map(Some)
21    }
22}
23
24register_kernel!(IsConstantKernelAdapter(VarBinVTable).lift());
25
26pub(super) fn compute_is_constant(iter: &mut dyn Iterator<Item = Option<&[u8]>>) -> bool {
27    let Some(first_value) = iter.next() else {
28        return false;
29    };
30    for v in iter {
31        if v != first_value {
32            return false;
33        }
34    }
35    true
36}