#[repr(transparent)]pub struct BitSlice<B: BitBlock>(pub [B]);
Expand description
Tuple Fields§
§0: [B]
Implementations§
source§impl<B: BitBlock> BitSlice<B>
impl<B: BitBlock> BitSlice<B>
sourcepub fn len_blocks(&self) -> usize
pub fn len_blocks(&self) -> usize
Returns the length of self
in blocks.
pub fn get_blocks<I: SliceIndex<[B]>>(&self, index: I) -> Option<&I::Output>
pub fn get_blocks_mut<I: SliceIndex<[B]>>( &mut self, index: I ) -> Option<&mut I::Output>
sourcepub fn blocks_mut(&mut self) -> IterMut<'_, B>
pub fn blocks_mut(&mut self) -> IterMut<'_, B>
Mutable iterates over the blocks in Self
sourcepub fn ones(&self) -> Ones<'_, B> ⓘ
pub fn ones(&self) -> Ones<'_, B> ⓘ
Iterates over the indices of the 1
s 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.
sourcepub fn zeros(&self) -> Zeros<'_, B> ⓘ
pub fn zeros(&self) -> Zeros<'_, B> ⓘ
Iterates over the indices of the 0
s 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.
sourcepub fn test(&self, idx: usize) -> Option<bool>
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.
sourcepub fn set_checked(&mut self, idx: usize) -> bool
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.
sourcepub fn reset_checked(&mut self, idx: usize) -> bool
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.
sourcepub fn bit_or_assign_iter<I: IntoIterator<Item = B>>(&mut self, other: I)
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.
sourcepub fn bit_or_assign(&mut self, other: &Self)
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
.
pub fn fill_ones_checked(&mut self, start: usize, length: NonZeroUsize) -> bool
pub fn fill_zeros_checked(&mut self, start: usize, length: NonZeroUsize) -> bool
source§impl<'a, B: BitBlock + 'a> BitSlice<B>
impl<'a, B: BitBlock + 'a> BitSlice<B>
sourcepub fn bit_or_assign_raw<I: IntoIterator<Item = &'a B>>(&mut self, other: I)
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>
impl<B: BitBlock> BitSlice<B>
sourcepub unsafe fn test_unchecked(&self, idx: usize) -> bool
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()
.