Struct bitmaps::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 Bitmap<128>

source

pub unsafe fn load_m128i(&self) -> __m128i

Available with target feature sse2 only.
source§

impl Bitmap<256>

source

pub unsafe fn load_m128i(&self) -> [__m128i; 2]

Available with target feature sse2 only.
source

pub unsafe fn load_m256i(&self) -> __m256i

Available with target feature avx only.
source§

impl Bitmap<512>

source

pub unsafe fn load_m128i(&self) -> [__m128i; 4]

Available with target feature sse2 only.
source

pub unsafe fn load_m256i(&self) -> [__m256i; 2]

Available with target feature avx only.
source§

impl Bitmap<768>

source

pub unsafe fn load_m128i(&self) -> [__m128i; 6]

Available with target feature sse2 only.
source

pub unsafe fn load_m256i(&self) -> [__m256i; 3]

Available with target feature avx only.
source§

impl Bitmap<1024>

source

pub unsafe fn load_m128i(&self) -> [__m128i; 8]

Available with target feature sse2 only.
source

pub unsafe fn load_m256i(&self) -> [__m256i; 4]

Available with target feature avx only.
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,

§

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,

§

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,

§

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 · source§

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<128>> for __m128i

source§

fn from(data: Bitmap<128>) -> 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<256>> for __m256i

source§

fn from(data: 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 From<__m128i> for Bitmap<128>

source§

fn from(data: __m128i) -> Self

Converts to this type from the input type.
source§

impl From<__m256i> for Bitmap<256>

source§

fn from(data: __m256i) -> 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 · source§

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,

§

type Item = usize

The type of the elements being iterated over.
§

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,

§

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 · source§

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

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

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

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

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

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method 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,

§

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> !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§

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.