use super::BitmapRef;
use crate::length::Length;
use std::ops::Not;
pub trait ValidityBitmap: BitmapRef {
#[inline]
fn is_null(&self, index: usize) -> Option<bool> {
self.is_valid(index).map(Not::not)
}
#[inline]
unsafe fn is_null_unchecked(&self, index: usize) -> bool {
!self.is_valid_unchecked(index)
}
#[inline]
fn null_count(&self) -> usize {
self.bitmap_ref()
.len()
.checked_sub(self.valid_count())
.expect("null count underflow")
}
#[inline]
fn is_valid(&self, index: usize) -> Option<bool> {
(index < self.bitmap_ref().len()).then(||
unsafe { self.is_valid_unchecked(index) })
}
#[inline]
unsafe fn is_valid_unchecked(&self, index: usize) -> bool {
self.bitmap_ref().get_unchecked(index)
}
#[inline]
fn valid_count(&self) -> usize {
(0..self.bitmap_ref().len())
.filter(|&index|
unsafe { self.is_valid_unchecked(index) })
.count()
}
#[inline]
fn any_null(&self) -> bool {
self.null_count() > 0
}
#[inline]
fn all_null(&self) -> bool {
self.null_count() == self.bitmap_ref().len()
}
#[inline]
fn any_valid(&self) -> bool {
self.valid_count() > 0
}
#[inline]
fn all_valid(&self) -> bool {
self.valid_count() == self.bitmap_ref().len()
}
}