Struct Bitmap

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

A compact array of bits.

The type used to store the bitmap will be the minimum unsigned integer type required to fit the number of bits, from u8 to u128. If the size is 1, bool is used. If the size exceeds 128, an array of u128 will be used, sized as appropriately. The maximum supported size is currently 1024, represented by an array [u128; 8].

Implementations§

Source§

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

Source

pub fn new() -> Self

Construct a bitmap with every bit set to false.

Source

pub fn mask(bits: usize) -> Self

Construct a bitmap where every bit with index less than bits is true, and every other bit is false.

Source

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

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

Source

pub fn into_value(self) -> <BitsImpl<SIZE> as Bits>::Store

Convert this bitmap into a value of the type of its backing store.

Source

pub fn as_value(&self) -> &<BitsImpl<SIZE> as Bits>::Store

Get a reference to this bitmap’s backing store.

Source

pub fn as_bytes(&self) -> &[u8]

Source

pub fn len(self) -> usize

Count the number of true bits in the bitmap.

Source

pub fn is_empty(self) -> bool

Test if the bitmap contains only false bits.

Source

pub fn is_full(self) -> bool

Test if the bitmap contains only true bits.

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.

Returns the previous value of the bit.

Source

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

Find the index of the first true bit in the bitmap.

Source

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

Find the index of the last true bit in the bitmap.

Source

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

Find the index of the first true bit in the bitmap after index.

Source

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

Find the index of the last true bit in the bitmap before index.

Source

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

Find the index of the first false bit in the bitmap.

Source

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

Find the index of the last false bit in the bitmap.

Source

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

Find the index of the first false bit in the bitmap after index.

Source

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

Find the index of the first false bit in the bitmap before index.

Source

pub fn invert(&mut self)

Invert all the bits in the bitmap.

Trait Implementations§

Source§

impl<const SIZE: usize> AsMut<[u8]> for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const SIZE: usize> AsRef<[u8]> for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const SIZE: usize> BitAnd for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = Bitmap<SIZE>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<const SIZE: usize> BitAndAssign for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<const SIZE: usize> BitOr for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = Bitmap<SIZE>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<const SIZE: usize> BitOrAssign for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<const SIZE: usize> BitXor for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = Bitmap<SIZE>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const SIZE: usize> BitXorAssign for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

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

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

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

Source§

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

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

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

Source§

fn default() -> Self

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

impl From<[u128; 2]> for Bitmap<256>

Source§

fn from(data: [u128; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 3]> for Bitmap<384>

Source§

fn from(data: [u128; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 4]> for Bitmap<512>

Source§

fn from(data: [u128; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 5]> for Bitmap<640>

Source§

fn from(data: [u128; 5]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 6]> for Bitmap<768>

Source§

fn from(data: [u128; 6]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 7]> for Bitmap<896>

Source§

fn from(data: [u128; 7]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 8]> for Bitmap<1024>

Source§

fn from(data: [u128; 8]) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<1024>> for [u128; 8]

Source§

fn from(bitmap: Bitmap<1024>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<256>> for [u128; 2]

Source§

fn from(bitmap: Bitmap<256>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<384>> for [u128; 3]

Source§

fn from(bitmap: Bitmap<384>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<512>> for [u128; 4]

Source§

fn from(bitmap: Bitmap<512>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<640>> for [u128; 5]

Source§

fn from(bitmap: Bitmap<640>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<768>> for [u128; 6]

Source§

fn from(bitmap: Bitmap<768>) -> Self

Converts to this type from the input type.
Source§

impl From<Bitmap<896>> for [u128; 7]

Source§

fn from(bitmap: Bitmap<896>) -> Self

Converts to this type from the input type.
Source§

impl<const SIZE: usize> Hash for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: Hash,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given [Hasher]. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given [Hasher]. Read more
Source§

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

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, SIZE>

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 SIZE: usize> Not for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = Bitmap<SIZE>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<const SIZE: usize> Ord for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an [Ordering] between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const SIZE: usize> PartialOrd for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const SIZE: usize> TryFrom<&[u8]> for Bitmap<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Error = ()

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

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.