Struct bitmap32::BitMap

source ·
#[repr(transparent)]
pub struct BitMap<B: BitBlock, const BLOCKS: usize>(pub [B; BLOCKS]);
Expand description

A bitmap that is internally represented as [B; BLOCKS].

Tuple Fields§

§0: [B; BLOCKS]

Implementations§

source§

impl<B: BitBlock, const BLOCKS: usize> BitMap<LE<B>, BLOCKS>where LE<B>: BitBlock,

source

pub fn from_raw_le(raw: [B; BLOCKS]) -> Self

Convenience function for creating little endian bitmaps. This is planned to become const when the needed rust features are stabilized.
For now, something like BitBlock::from_raw([LE(0b00100111), LE(0b01100011)]) may be used instead.

source§

impl<B: BitBlock, const BLOCKS: usize> BitMap<B, BLOCKS>

source

pub const fn new() -> Self

Creates a zero-initialized bitmap

source

pub const fn from_raw(raw: [B; BLOCKS]) -> Self

Same as raw.into() but usable in const contexts;

Methods from Deref<Target = BitSlice<B>>§

source

pub fn len_blocks(&self) -> usize

Returns the length of self in blocks.

source

pub fn len_bits(&self) -> usize

Returns the length of self in bits.

source

pub fn get_blocks<I: SliceIndex<[B]>>(&self, index: I) -> Option<&I::Output>

source

pub fn get_blocks_mut<I: SliceIndex<[B]>>( &mut self, index: I ) -> Option<&mut I::Output>

source

pub fn blocks(&self) -> Iter<'_, B>

Iterates over the blocks in Self

source

pub fn blocks_mut(&mut self) -> IterMut<'_, B>

Mutable iterates over the blocks in Self

source

pub fn bits(&self) -> Bits<'_, B>

Iterates over the bits in self.

source

pub fn ones(&self) -> Ones<'_, B>

Iterates over the indices of the 1s in self. This is equivalent to self.bits().enumerate().filter_map(|(i, bit)| bit.then_some(i)), but it makes use of several optimizations and usually a count leading zero instruction or something similar.

source

pub fn zeros(&self) -> Zeros<'_, B>

Iterates over the indices of the 0s in self. This is equivalent to self.bits().enumerate().filter_map(|(i, bit)| (!bit).then_some(i)), but it makes use of several optimizations and usually a count leading zero instruction or something similar.

source

pub fn test(&self, idx: usize) -> Option<bool>

Returns true if the bit at idx is a 1. If idx is out of range, None is returned.

source

pub fn set_checked(&mut self, idx: usize) -> bool

Sets the bit at idx to 1. If idx is out of range, false is returned.

source

pub fn reset_checked(&mut self, idx: usize) -> bool

Sets the bit at idx to 0. If idx is out of range, false is returned.

source

pub fn clear(&mut self)

Zeros all of the bits in self.

source

pub fn bit_or_assign_iter<I: IntoIterator<Item = B>>(&mut self, other: I)

Does a BitOrAssign between rhs and self. If rhs is bigger than self, the overflowing bits are ignored.

source

pub fn bit_or_assign(&mut self, other: &Self)

Does a BitOrAssign between rhs and self. If rhs is bigger than self, the overflowing bits are ignored.
This function is purely a convinience function for Self::bit_or_assign_iter.

Note: the reason why the BitOrAssign trait isn’t used is because it requires that Self is Sized.

source

pub fn fill_ones_checked(&mut self, start: usize, length: NonZeroUsize) -> bool

source

pub fn fill_zeros_checked(&mut self, start: usize, length: NonZeroUsize) -> bool

source

pub fn bit_or_assign_raw<I: IntoIterator<Item = &'a B>>(&mut self, other: I)

Does a BitOrAssign between rhs and self. If rhs is bigger than self, the overflowing bits are ignored.
This function is purely a convinience function for Self::bit_or_assign_iter.

Example
let mut foo = BitMap::from([0b00110000u8, 0b00010010u8]);

foo.bit_or_assign_raw(&[0b10000000]);
assert_eq!(foo.test(0), Some(true));
assert_eq!(foo.test(8), Some(false));
source

pub unsafe fn test_unchecked(&self, idx: usize) -> bool

Returns true if the bit at idx is 1.

Safety

This function is safe if and only if idx < self.len_blocks().

source

pub unsafe fn set_unchecked(&mut self, idx: usize)

Sets the bit at idx to 1.

Safety

This function is safe if and only if idx < self.len_blocks().

source

pub unsafe fn reset_unchecked(&mut self, idx: usize)

Sets the bit at idx to 0

Safety

This function is safe if and only if idx < self.len_blocks().

source

pub unsafe fn fill_ones_unchecked(&mut self, start: usize, length: NonZeroUsize)

Fills a region starting at bit index start with 1s. TODO: test

Safety

TODO

source

pub unsafe fn fill_zeros_unchecked( &mut self, start: usize, length: NonZeroUsize )

Fills a region starting at bit index start with 0s. TODO: test

Safety

TODO

Trait Implementations§

source§

impl<B: BitBlock, const BLOCKS: usize> AsMut<[B]> for BitMap<B, BLOCKS>

source§

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

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

impl<B: BitBlock, const BLOCKS: usize> AsMut<[B; BLOCKS]> for BitMap<B, BLOCKS>

source§

fn as_mut(&mut self) -> &mut [B; BLOCKS]

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

impl<B: BitBlock, const BLOCKS: usize> AsMut<BitSlice<B>> for BitMap<B, BLOCKS>

source§

fn as_mut(&mut self) -> &mut BitSlice<B>

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

impl<B: BitBlock, const BLOCKS: usize> AsRef<[B]> for BitMap<B, BLOCKS>

source§

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

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

impl<B: BitBlock, const BLOCKS: usize> AsRef<[B; BLOCKS]> for BitMap<B, BLOCKS>

source§

fn as_ref(&self) -> &[B; BLOCKS]

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

impl<B: BitBlock, const BLOCKS: usize> AsRef<BitSlice<B>> for BitMap<B, BLOCKS>

source§

fn as_ref(&self) -> &BitSlice<B>

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

impl<B: Clone + BitBlock, const BLOCKS: usize> Clone for BitMap<B, BLOCKS>

source§

fn clone(&self) -> BitMap<B, BLOCKS>

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<B: BitBlock, const BLOCKS: usize> Debug for BitMap<B, BLOCKS>

source§

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

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

impl<B: BitBlock, const BLOCKS: usize> Default for BitMap<B, BLOCKS>

source§

fn default() -> Self

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

impl<B: BitBlock, const BLOCKS: usize> Deref for BitMap<B, BLOCKS>

§

type Target = BitSlice<B>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<B: BitBlock, const BLOCKS: usize> DerefMut for BitMap<B, BLOCKS>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<B: BitBlock, const BLOCKS: usize> From<[B; BLOCKS]> for BitMap<B, BLOCKS>

source§

fn from(value: [B; BLOCKS]) -> Self

Converts to this type from the input type.
source§

impl<B: BitBlock, const BLOCKS: usize> From<BitMap<B, BLOCKS>> for [B; BLOCKS]

source§

fn from(value: BitMap<B, BLOCKS>) -> Self

Converts to this type from the input type.
source§

impl<B: Hash + BitBlock, const BLOCKS: usize> Hash for BitMap<B, BLOCKS>

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

Auto Trait Implementations§

§

impl<B, const BLOCKS: usize> RefUnwindSafe for BitMap<B, BLOCKS>where B: RefUnwindSafe,

§

impl<B, const BLOCKS: usize> Send for BitMap<B, BLOCKS>where B: Send,

§

impl<B, const BLOCKS: usize> Sync for BitMap<B, BLOCKS>where B: Sync,

§

impl<B, const BLOCKS: usize> Unpin for BitMap<B, BLOCKS>where B: Unpin,

§

impl<B, const BLOCKS: usize> UnwindSafe for BitMap<B, BLOCKS>where B: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.