Struct bitmap32::slice::BitSlice

source ·
#[repr(transparent)]
pub struct BitSlice<B: BitBlock>(pub [B]);
Expand description

Represents a slice of bits. B is the internal representation of the blocks used for the BitSlice

Tuple Fields§

§0: [B]

Implementations§

source§

impl<B: BitBlock> 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§

impl<'a, B: BitBlock + 'a> BitSlice<B>

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§

impl<B: BitBlock> BitSlice<B>

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> AsMut<[B]> for BitSlice<B>

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> AsMut<BitSlice<B>> for [B]

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> 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> AsRef<[B]> for BitSlice<B>

source§

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

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

impl<B: BitBlock> AsRef<BitSlice<B>> for [B]

source§

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

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: BitBlock> Debug for BitSlice<B>

source§

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

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

impl<B: Hash + BitBlock> Hash for BitSlice<B>

source§

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

Feeds this value into the given Hasher. Read more

Auto Trait Implementations§

§

impl<B> RefUnwindSafe for BitSlice<B>where B: RefUnwindSafe,

§

impl<B> Send for BitSlice<B>where B: Send,

§

impl<B> !Sized for BitSlice<B>

§

impl<B> Sync for BitSlice<B>where B: Sync,

§

impl<B> Unpin for BitSlice<B>where B: Unpin,

§

impl<B> UnwindSafe for BitSlice<B>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