pub struct BitmaskV {
pub bitmask: Arc<Bitmask>,
pub offset: usize,
/* private fields */
}Expand description
§BitmaskView
Zero-copy, bounds-checked window over a Bitmask.
§Fields
bitmask: backingBitmask(shared viaArc).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: Arc<Bitmask>The 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 BitmaskV
impl BitmaskV
Sourcepub fn new(bitmask: Bitmask, offset: usize, len: usize) -> BitmaskV
pub fn new(bitmask: Bitmask, offset: usize, len: usize) -> BitmaskV
Construct a view over bitmask[offset..offset+len).
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 a Bitmask copy of the view.
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).
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).
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) -> BitmaskV
pub fn slice(&self, offset: usize, len: usize) -> BitmaskV
Slices the view further by logical offset and len (relative to this window).
Trait Implementations§
Source§impl Concatenate for BitmaskV
impl Concatenate for BitmaskV
Source§fn concat(self, other: BitmaskV) -> Result<BitmaskV, MinarrowError>
fn concat(self, other: BitmaskV) -> Result<BitmaskV, MinarrowError>
Concatenates two bitmask views by materialising both to owned bitmasks, concatenating them, and wrapping the result back in a view.
§Notes
- This operation copies data from both views to create owned bitmasks.
- The resulting view has offset=0 and length equal to the combined length.
Source§impl Index<usize> for BitmaskV
impl Index<usize> for BitmaskV
Source§fn index(&self, index: usize) -> &<BitmaskV as Index<usize>>::Output
fn index(&self, index: usize) -> &<BitmaskV as Index<usize>>::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.