Skip to main content

Bitmap

Struct Bitmap 

Source
pub struct Bitmap<const N: usize>
where BitsImpl<N>: Bits,
{ /* private fields */ }
Expand description

A fixed capacity inline bitmap of N bits.

Used as the occupancy map inside SparseChunk. Supports N in 1..=1024; other sizes fail to compile.

Implementations§

Source§

impl<const N: usize> Bitmap<N>
where BitsImpl<N>: Bits,

Source

pub fn new() -> Self

Construct a bitmap with every bit clear.

Source

pub fn from_value(data: <BitsImpl<N> as Bits>::Store) -> Self

Construct a bitmap from a value of the same type as its backing store.

Bits at or above index N are cleared, keeping the bitmap coherent: len(), is_empty() and is_full() only ever count bits below N.

Source

pub fn len(self) -> usize

Count the number of set bits.

Source

pub fn is_empty(self) -> bool

Test if the bitmap contains only clear bits.

Source

pub fn is_full(self) -> bool

Test if all N bits are set.

Source

pub fn get(self, index: usize) -> bool

Get the value of the bit at a given index.

Source

pub fn set(&mut self, index: usize, value: bool) -> bool

Set the value of the bit at a given index, returning the previous value.

index must be < N (debug-asserted, as with the bitmaps crate); writing a padding bit in a release build would create an incoherent state, so len() would count a bit no scan or iterator can see.

Source

pub fn first_index(self) -> Option<usize>

Find the index of the first set bit.

Source

pub fn next_index(self, index: usize) -> Option<usize>

Find the index of the first set bit strictly after index.

Source

pub fn last_index(self) -> Option<usize>

Find the index of the last set bit.

Source

pub fn prev_index(self, index: usize) -> Option<usize>

Find the index of the last set bit strictly before index.

Source

pub fn first_false_index(self) -> Option<usize>

Find the index of the first clear bit.

Source

pub fn next_false_index(self, index: usize) -> Option<usize>

Find the index of the first clear bit strictly after index.

Trait Implementations§

Source§

impl<const N: usize> Clone for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

impl<const N: usize> Debug for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Eq for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

impl<'a, const N: usize> IntoIterator for &'a Bitmap<N>
where BitsImpl<N>: Bits,

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, N>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const N: usize> PartialEq for Bitmap<N>
where BitsImpl<N>: Bits,

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> StructuralPartialEq for Bitmap<N>
where BitsImpl<N>: Bits,

Auto Trait Implementations§

§

impl<const N: usize> !Freeze for Bitmap<N>

§

impl<const N: usize> !RefUnwindSafe for Bitmap<N>

§

impl<const N: usize> !Send for Bitmap<N>

§

impl<const N: usize> !Sync for Bitmap<N>

§

impl<const N: usize> !Unpin for Bitmap<N>

§

impl<const N: usize> !UnsafeUnpin for Bitmap<N>

§

impl<const N: usize> !UnwindSafe for Bitmap<N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.