vortex_array/arrays/primitive/compute/
is_constant.rs1use vortex_dtype::{NativePType, match_each_native_ptype};
2
3use crate::arrays::{PrimitiveArray, PrimitiveEncoding};
4use crate::compute::{IsConstantFn, IsConstantOpts};
5use crate::variants::PrimitiveArrayTrait;
6
7impl IsConstantFn<&PrimitiveArray> for PrimitiveEncoding {
8 fn is_constant(
9 &self,
10 array: &PrimitiveArray,
11 _opts: &IsConstantOpts,
12 ) -> vortex_error::VortexResult<Option<bool>> {
13 let is_constant = match_each_native_ptype!(array.ptype(), |$P| {
14 compute_is_constant(array.as_slice::<$P>())
15 });
16
17 Ok(Some(is_constant))
18 }
19}
20
21fn compute_is_constant<T: NativePType>(values: &[T]) -> bool {
23 let first_value = values[0];
24
25 for value in &values[1..] {
26 if !value.is_eq(first_value) {
27 return false;
28 }
29 }
30
31 true
32}