Skip to main content

BitmapReader

Struct BitmapReader 

Source
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>

Source

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.

Source

pub fn bit_count(&self) -> u64

Returns the total number of valid bits in this bitmap.

Source

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.

Source

pub fn count_set_bits(&self) -> u64

Count the number of set (1) bits in the valid range.

Source

pub fn count_clear_bits(&self) -> u64

Count the number of clear (0) bits in the valid range.

Source

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.

Source

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.

Source

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.

Source

pub fn iter_set_bits(&self) -> SetBitsIter<'_> ⓘ

Iterate over the indices of all set (1) bits in ascending order.

Source

pub fn iter_clear_bits(&self) -> ClearBitsIter<'_> ⓘ

Iterate over the indices of all clear (0) bits in ascending order.

Auto Trait Implementations§

§

impl<'a> Freeze for BitmapReader<'a>

§

impl<'a> RefUnwindSafe for BitmapReader<'a>

§

impl<'a> Send for BitmapReader<'a>

§

impl<'a> Sync for BitmapReader<'a>

§

impl<'a> Unpin for BitmapReader<'a>

§

impl<'a> UnsafeUnpin for BitmapReader<'a>

§

impl<'a> UnwindSafe for BitmapReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.