pub struct BitmaskV<'a> {
pub bitmask: &'a Bitmask,
pub offset: usize,
/* private fields */
}Expand description
§BitmaskView
Zero-copy, bounds-checked window over a Bitmask.
§Fields
bitmask: borrowed reference to the backingBitmask.offset: start bit position in the parent mask.len: number of bits in the view.
§Behaviour
- All indexing is relative to the view’s start.
- All accesses are in-bounds (panics if violated).
- No allocation or buffer copying occurs when creating or slicing views.
§Example
use minarrow::Bitmask;
use minarrow::BitmaskV;
let mask = Bitmask::from_bools(&[true, false, true, true, false]);
let view = BitmaskV::new(&mask, 1, 3); // window: false, true, true
assert_eq!(view.len(), 3);
assert!(!view.get(0));
assert!(view.get(1));
assert!(view.get(2));Fields§
§bitmask: &'a BitmaskThe outer bitmask that this view is derived from - we retain a reference to it. Importantly, this is the full bitmask - not the view, and thus should not be accessed as though it were the view subset.
offset: usizeThe index offset from 0 that for where this view starts from the outer bitmask
Implementations§
Source§impl<'a> BitmaskV<'a>
impl<'a> BitmaskV<'a>
Sourcepub fn new(bitmask: &'a Bitmask, offset: usize, len: usize) -> Self
pub fn new(bitmask: &'a Bitmask, offset: usize, len: usize) -> Self
Construct a view over bitmask[offset..offset+len).
Sourcepub unsafe fn get_unchecked(&self, i: usize) -> bool
pub unsafe fn get_unchecked(&self, i: usize) -> bool
Returns the value at logical index i within the view, skipping the
bounds check.
Element-wise kernels read a flagged null_mask (valid) bit per row, so the checked
get costs a comparison in the innermost loop. This is
the unchecked counterpart for loops that have already established
i < len.
§Safety
i must be less than the view’s length.
Sourcepub fn as_bytes_window(&self) -> (&[u8], usize, usize)
pub fn as_bytes_window(&self) -> (&[u8], usize, usize)
Returns a slice of the bitmask’s bytes
Due to the booleans being bitpacked in a u8,
the slice retains:
Pos 0: Buffer: The bitpacked u8 buffer.
Pos 1: Offset: Bit offset indicating where it starts in that byte.
Pos 2: Length: Logical length in bits of the slice
Sourcepub fn to_bitmask(&self) -> Bitmask
pub fn to_bitmask(&self) -> Bitmask
Returns an owned Bitmask for the window.
If the view covers the entire backing bitmask, returns a clone of the
underlying Bitmask (cheap for Shared storage; a byte memcpy for
Owned storage). Otherwise falls back to bit-by-bit slice_clone,
which has to honour bit alignment across the window boundary.
Sourcepub fn iter_set(&self) -> impl Iterator<Item = usize> + '_
pub fn iter_set(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over all set bits (indices relative to the window).
The scan walks the backing mask one 64-bit word at a time from the window’s bit offset, so a word with no set bits costs a single comparison and each set bit is located through a trailing-zeros count.
Sourcepub fn iter_cleared(&self) -> impl Iterator<Item = usize> + '_
pub fn iter_cleared(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over all cleared bits (indices relative to the window).
The scan walks the backing mask one 64-bit word at a time from the window’s bit offset, so a fully valid word costs a single comparison and each null is located through a trailing-zeros count.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Counts number of set bits in the view.
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Counts number of cleared bits in the view.
Sourcepub fn has_cleared(&self) -> bool
pub fn has_cleared(&self) -> bool
Returns true if any bit in the view is cleared.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
Slices the view further by logical offset and len (relative to this window).
Trait Implementations§
impl<'a> Copy for BitmaskV<'a>
Source§impl<'a> From<&'a Array> for BitmaskV<'a>
Extract the boolean data from an Array. Panics if not a BooleanArray variant.
impl<'a> From<&'a Array> for BitmaskV<'a>
Extract the boolean data from an Array. Panics if not a BooleanArray variant.
Source§impl<'a> From<&'a ArrayV> for BitmaskV<'a>
Available on crate feature views only.Extract the boolean data from an ArrayV, preserving the view’s offset and length.
Panics if the underlying array is not a BooleanArray variant.
impl<'a> From<&'a ArrayV> for BitmaskV<'a>
views only.Extract the boolean data from an ArrayV, preserving the view’s offset and length. Panics if the underlying array is not a BooleanArray variant.
Source§impl<'a, T> From<&'a BooleanArray<T>> for BitmaskV<'a>
View over a BooleanArray’s data bitmask with zero offset.
impl<'a, T> From<&'a BooleanArray<T>> for BitmaskV<'a>
View over a BooleanArray’s data bitmask with zero offset.
Source§fn from(arr: &'a BooleanArray<T>) -> Self
fn from(arr: &'a BooleanArray<T>) -> Self
Source§impl<'a> From<BitmaskV<'a>> for Value
Available on crate feature views only.Wrap a BitmaskV as Value::ArrayView of a BooleanArray. The bitmask
data is taken as the BooleanArray’s data; null_mask is None since
BitmaskV carries no separate null mask.
impl<'a> From<BitmaskV<'a>> for Value
views only.Wrap a BitmaskV as Value::ArrayView of a BooleanArray. The bitmask
data is taken as the BooleanArray’s data; null_mask is None since
BitmaskV carries no separate null mask.
Source§impl<'a> Index<usize> for BitmaskV<'a>
impl<'a> Index<usize> for BitmaskV<'a>
Source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Returns a reference to a constant true or false value depending on the bit at index.
Note: This does not return a reference into the underlying bitmask storage.
The reference points to a compiler-promoted static constant, so its address is
unrelated to the internal buffer. Use Self::get if you need the value directly.
Source§impl<'a> Shape for BitmaskV<'a>
impl<'a> Shape for BitmaskV<'a>
impl<'a> StructuralPartialEq for BitmaskV<'a>
Source§impl<'a> TryFrom<&'a Value> for BitmaskV<'a>
Available on crate feature views only.Borrow a Value as a windowed BitmaskV over its boolean data.
impl<'a> TryFrom<&'a Value> for BitmaskV<'a>
views only.Borrow a Value as a windowed BitmaskV over its boolean data.
The view borrows the Value, so the Value must outlive it. An
ArrayView preserves the inner view’s offset and length. An owned
Array windows the whole boolean column.
Auto Trait Implementations§
impl<'a> Freeze for BitmaskV<'a>
impl<'a> RefUnwindSafe for BitmaskV<'a>
impl<'a> Send for BitmaskV<'a>
impl<'a> Sync for BitmaskV<'a>
impl<'a> Unpin for BitmaskV<'a>
impl<'a> UnsafeUnpin for BitmaskV<'a>
impl<'a> UnwindSafe for BitmaskV<'a>
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CustomValue for T
impl<T> CustomValue for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more