pub struct BitVec<W: BitWord> { /* private fields */ }
Expand description
A growable, heap-allocated bit vector.
BitVec
provides a contiguous growable array of bits, similar to Vec<bool>
, but much more efficient.
The underlying storage is a raw pointer to a bitset, and the length and capacity are tracked in bits.
Implementations§
Source§impl<W: BitWord> BitVec<W>
impl<W: BitWord> BitVec<W>
Sourcepub fn new_uninit(bit_len: usize) -> Self
pub fn new_uninit(bit_len: usize) -> Self
Sourcepub fn new(bit_len: usize) -> Self
pub fn new(bit_len: usize) -> Self
Creates a new, zero-initialized bit vector with the given number of bits.
§Arguments
bit_len
- The number of bits to allocate.
Sourcepub fn resize(&mut self, new_bit_len: usize)
pub fn resize(&mut self, new_bit_len: usize)
Resizes the bit vector to the new length in bits.
If the new length is greater than the current length, new bits are zero-initialized. If the new length is less, excess bits are dropped.
§Arguments
new_bit_len
- The new length in bits.
Sourcepub fn as_view_mut(&self) -> BitViewMut<'_, W>
pub fn as_view_mut(&self) -> BitViewMut<'_, W>
Returns a mutable view of the bit vector.
Sourcepub fn slice(&self, offset: usize, len: usize) -> BitSpan<'_, W>
pub fn slice(&self, offset: usize, len: usize) -> BitSpan<'_, W>
Returns a slice of the bit vector as a BitSpan
.
§Arguments
offset
- The starting bit index.len
- The number of bits in the slice.
pub fn slice_mut(&self, offset: usize, len: usize) -> BitSpanMut<'_, W>
Trait Implementations§
Source§impl<W: BitWord> BitRead for BitVec<W>
impl<W: BitWord> BitRead for BitVec<W>
Source§impl<W: BitWord> BitWrite for BitVec<W>
impl<W: BitWord> BitWrite for BitVec<W>
Source§fn test_and_set(&mut self, idx: usize) -> bool
fn test_and_set(&mut self, idx: usize) -> bool
Sets the bit at position
idx
and returns the previous value.Auto Trait Implementations§
impl<W> Freeze for BitVec<W>
impl<W> RefUnwindSafe for BitVec<W>where
W: RefUnwindSafe,
impl<W> !Send for BitVec<W>
impl<W> !Sync for BitVec<W>
impl<W> Unpin for BitVec<W>
impl<W> UnwindSafe for BitVec<W>where
W: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more