pub struct BitmapReader<'a> { /* private fields */ }Expand description
A read-only view over a bitmap stored as a byte slice.
bit_count specifies the number of valid bits, which may be less than
data.len() * 8 (e.g. when the last byte is only partially used).
Implementations§
Source§impl<'a> BitmapReader<'a>
impl<'a> BitmapReader<'a>
Sourcepub fn new(data: &'a [u8], bit_count: u64) -> Self
pub fn new(data: &'a [u8], bit_count: u64) -> Self
Create a new bitmap reader.
bit_count is the number of valid bits. Bits beyond bit_count
(in the last partial byte) are ignored by counting and iteration methods.
Sourcepub fn is_bit_set(&self, index: u64) -> bool
pub fn is_bit_set(&self, index: u64) -> bool
Test whether the bit at index is set (1).
Returns false if index is out of range.
Sourcepub fn count_set_bits(&self) -> u64
pub fn count_set_bits(&self) -> u64
Count the number of set (1) bits in the valid range.
Sourcepub fn count_clear_bits(&self) -> u64
pub fn count_clear_bits(&self) -> u64
Count the number of clear (0) bits in the valid range.
Sourcepub fn highest_set_bit(&self) -> Option<u64>
pub fn highest_set_bit(&self) -> Option<u64>
Find the index of the highest set bit, scanning from the end.
Returns None if no bits are set.
Sourcepub fn highest_clear_bit(&self) -> Option<u64>
pub fn highest_clear_bit(&self) -> Option<u64>
Find the index of the highest clear (0) bit, scanning from the end. Useful for “set = free” bitmaps (UFS / JFS / AFFS) where the last-allocated position translates to the highest clear bit.
Returns None if all bits in the valid range are set.
Sourcepub fn lowest_clear_bit(&self) -> Option<u64>
pub fn lowest_clear_bit(&self) -> Option<u64>
Find the index of the lowest clear (0) bit, scanning from the start.
Returns None if all bits are set.
Sourcepub fn iter_set_bits(&self) -> SetBitsIter<'_> ⓘ
pub fn iter_set_bits(&self) -> SetBitsIter<'_> ⓘ
Iterate over the indices of all set (1) bits in ascending order.
Sourcepub fn iter_clear_bits(&self) -> ClearBitsIter<'_> ⓘ
pub fn iter_clear_bits(&self) -> ClearBitsIter<'_> ⓘ
Iterate over the indices of all clear (0) bits in ascending order.