use std::ops::{BitAnd, BitOr};
use polars_error::{polars_ensure, PolarsResult};
use crate::array::Array;
use crate::bitmap::{and_not, ternary, Bitmap};
pub fn combine_validities_and3(
opt1: Option<&Bitmap>,
opt2: Option<&Bitmap>,
opt3: Option<&Bitmap>,
) -> Option<Bitmap> {
match (opt1, opt2, opt3) {
(Some(a), Some(b), Some(c)) => Some(ternary(a, b, c, |x, y, z| x & y & z)),
(Some(a), Some(b), None) => Some(a.bitand(b)),
(Some(a), None, Some(c)) => Some(a.bitand(c)),
(None, Some(b), Some(c)) => Some(b.bitand(c)),
(Some(a), None, None) => Some(a.clone()),
(None, Some(b), None) => Some(b.clone()),
(None, None, Some(c)) => Some(c.clone()),
(None, None, None) => None,
}
}
pub fn combine_validities_and(opt_l: Option<&Bitmap>, opt_r: Option<&Bitmap>) -> Option<Bitmap> {
match (opt_l, opt_r) {
(Some(l), Some(r)) => Some(l.bitand(r)),
(None, Some(r)) => Some(r.clone()),
(Some(l), None) => Some(l.clone()),
(None, None) => None,
}
}
pub fn combine_validities_or(opt_l: Option<&Bitmap>, opt_r: Option<&Bitmap>) -> Option<Bitmap> {
match (opt_l, opt_r) {
(Some(l), Some(r)) => Some(l.bitor(r)),
_ => None,
}
}
pub fn combine_validities_and_not(
opt_l: Option<&Bitmap>,
opt_r: Option<&Bitmap>,
) -> Option<Bitmap> {
match (opt_l, opt_r) {
(Some(l), Some(r)) => Some(and_not(l, r)),
(None, Some(r)) => Some(!r),
(Some(l), None) => Some(l.clone()),
(None, None) => None,
}
}
#[inline]
pub fn check_same_len(lhs: &dyn Array, rhs: &dyn Array) -> PolarsResult<()> {
polars_ensure!(lhs.len() == rhs.len(), ComputeError:
"arrays must have the same length"
);
Ok(())
}