diff --git a/src/compute/bitwise.rs b/src/compute/bitwise.rs index 4a9d981f33e..37c26542b84 100644 --- a/src/compute/bitwise.rs +++ b/src/compute/bitwise.rs @@ -5,7 +5,7 @@ use crate::array::PrimitiveArray; use crate::compute::arity::{binary, unary}; use crate::types::NativeType; -/// Performs `OR` operation on two arrays. +/// Performs `OR` operation on two [`PrimitiveArray`]s. /// # Panic /// This function errors when the arrays have different lengths. pub fn or(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveArray @@ -15,7 +15,7 @@ where binary(lhs, rhs, lhs.data_type().clone(), |a, b| a | b) } -/// Performs `XOR` operation between two arrays. +/// Performs `XOR` operation between two [`PrimitiveArray`]s. /// # Panic /// This function errors when the arrays have different lengths. pub fn xor(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveArray @@ -25,7 +25,7 @@ where binary(lhs, rhs, lhs.data_type().clone(), |a, b| a ^ b) } -/// Performs `AND` operation on two arrays. +/// Performs `AND` operation on two [`PrimitiveArray`]s. /// # Panic /// This function panics when the arrays have different lengths. pub fn and(lhs: &PrimitiveArray, rhs: &PrimitiveArray) -> PrimitiveArray @@ -43,3 +43,33 @@ where let op = move |a: T| !a; unary(array, op, array.data_type().clone()) } + +/// Performs `OR` operation between a [`PrimitiveArray`] and scalar. +/// # Panic +/// This function errors when the arrays have different lengths. +pub fn or_scalar(lhs: &PrimitiveArray, rhs: &T) -> PrimitiveArray +where + T: NativeType + BitOr, +{ + unary(lhs, |a| a | *rhs, lhs.data_type().clone()) +} + +/// Performs `XOR` operation between a [`PrimitiveArray`] and scalar. +/// # Panic +/// This function errors when the arrays have different lengths. +pub fn xor_scalar(lhs: &PrimitiveArray, rhs: &T) -> PrimitiveArray +where + T: NativeType + BitXor, +{ + unary(lhs, |a| a ^ *rhs, lhs.data_type().clone()) +} + +/// Performs `AND` operation between a [`PrimitiveArray`] and scalar. +/// # Panic +/// This function panics when the arrays have different lengths. +pub fn and_scalar(lhs: &PrimitiveArray, rhs: &T) -> PrimitiveArray +where + T: NativeType + BitAnd, +{ + unary(lhs, |a| a & *rhs, lhs.data_type().clone()) +}