Struct BitVec

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

Source

pub fn new_uninit(bit_len: usize) -> Self

Creates a new, uninitialized bit vector with the given number of bits.

§Arguments
  • bit_len - The number of bits to allocate.
§Safety

The bits are uninitialized and may contain garbage values.

Source

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.
Source

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.
Source

pub fn iter(&self) -> Iter<'_, W>

Returns an iterator over the bits of the vector.

Source

pub fn as_view(&self) -> BitView<'_, W>

Returns a read-only view of the bit vector.

Source

pub fn as_view_mut(&self) -> BitViewMut<'_, W>

Returns a mutable view of the bit vector.

Source

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.
Source

pub fn slice_mut(&self, offset: usize, len: usize) -> BitSpanMut<'_, W>

Trait Implementations§

Source§

impl<W: BitWord> BitRead for BitVec<W>

Source§

type Iter<'b> = Iter<'b, W> where Self: 'b

Source§

fn len(&self) -> usize

Returns the number of bits in the bitset.
Source§

fn is_empty(&self) -> bool

Returns true if the bitset contains no set bits.
Source§

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

Returns true if the bit at position idx is set.
Source§

fn count_ones(&self) -> usize

Returns the number of set bits.
Source§

fn all(&self) -> bool

Returns true if all bits are set.
Source§

fn any(&self) -> bool

Returns true if any bit is set.
Source§

fn iter(&self) -> Self::Iter<'_>

Source§

fn none(&self) -> bool

Source§

impl<W: BitWord> BitWrite for BitVec<W>

Source§

fn set(&mut self, idx: usize)

Sets the bit at position idx.
Source§

fn reset(&mut self, idx: usize)

Clears the bit at position idx.
Source§

fn flip(&mut self, idx: usize)

flit the bit at position idx.
Source§

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

Sets the bit at position idx and returns the previous value.
Source§

fn fill(&mut self)

Sets all bits to 1.
Source§

fn clear(&mut self)

Clears all bits to 0.
Source§

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

return and clear bit at idx.
Source§

fn replace(&mut self, idx: usize, value: bool) -> bool

set bit to value, return old.
Source§

impl<T: Debug + BitWord> Debug for BitVec<T>

Implements the Debug trait for BitFixed.

This provides a human-readable representation of the bitset for debugging.

Source§

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

Formats the bitset for debugging.

Source§

impl<W: BitWord> Drop for BitVec<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.