pub struct BitString { /* private fields */ }Implementations§
Source§impl BitString
impl BitString
Sourcepub fn as_words(&self) -> &[u64]
pub fn as_words(&self) -> &[u64]
Returns the internal little-endian words.
Bit index i is stored in word i / 64, bit offset i % 64.
Unused high bits in the last word are guaranteed to be zero.
pub fn first(&self) -> Option<bool>
Sourcepub fn get_chunk(&self, bit_start: usize) -> u64
pub fn get_chunk(&self, bit_start: usize) -> u64
Reads up to 64 bits starting at bit_start, returning them in the
low bits of a u64.
Bits beyond self.len() are treated as zero.
pub fn last(&self) -> Option<bool>
pub fn to_bool_vec(&self) -> Vec<bool>
Source§impl BitString
impl BitString
Sourcepub fn and(&self, rhs: &Self) -> Result<Self, BitStringLenMismatch>
pub fn and(&self, rhs: &Self) -> Result<Self, BitStringLenMismatch>
Returns self & rhs without mutating either input.
Sourcepub fn and_assign(&mut self, rhs: &Self) -> Result<(), BitStringLenMismatch>
pub fn and_assign(&mut self, rhs: &Self) -> Result<(), BitStringLenMismatch>
Replaces self with self & rhs.
Source§impl BitString
impl BitString
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Returns the number of bits set to 1.
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Returns the number of bits set to 0.
Source§impl BitString
impl BitString
Sourcepub fn not_assign(&mut self)
pub fn not_assign(&mut self)
Replaces self with !self.
Source§impl BitString
impl BitString
pub fn or(&self, rhs: &Self) -> Result<Self, BitStringLenMismatch>
pub fn or_assign(&mut self, rhs: &Self) -> Result<(), BitStringLenMismatch>
Source§impl BitString
impl BitString
pub fn xor(&self, rhs: &Self) -> Result<Self, BitStringLenMismatch>
pub fn xor_assign(&mut self, rhs: &Self) -> Result<(), BitStringLenMismatch>
Source§impl BitString
impl BitString
Sourcepub fn from_words(words: &[u64], len: usize) -> Option<Self>
pub fn from_words(words: &[u64], len: usize) -> Option<Self>
Constructs a bit string from packed little-endian words.
The input must contain exactly enough words for len.
Unused high bits in the last word are masked out.
Source§impl BitString
impl BitString
Sourcepub fn push_bit_string(&mut self, rhs: &Self)
pub fn push_bit_string(&mut self, rhs: &Self)
Appends the bits of rhs to self.
When self has spare capacity the operation is performed in-place
without allocation.
Sourcepub fn insert_bit_string(&mut self, index: usize, rhs: &Self)
pub fn insert_bit_string(&mut self, index: usize, rhs: &Self)
Inserts the bits of rhs at index, shifting the tail right.
index is clamped to [0, self.bit_len()] — an out-of-bounds index
inserts at the end (equivalent to push_bit_string).
When spare capacity is available and rhs.bit_len() >= 64, the tail is
shifted in-place without allocation.
Source§impl BitString
impl BitString
Sourcepub fn drain_interval(&self, interval: UsizeCO) -> Self
pub fn drain_interval(&self, interval: UsizeCO) -> Self
Borrowing variant: returns a new BitString with interval removed;
self is unchanged.
The interval is clamped to [0, self.bit_len()). An interval that lies
entirely beyond the bit string length returns a clone of self.
Sourcepub fn drain_interval_assign(&mut self, interval: UsizeCO)
pub fn drain_interval_assign(&mut self, interval: UsizeCO)
Assigning variant: removes interval from self.
Always allocates a fresh buffer and swaps it in — profiling shows that
copy_bits → paste_to via memcpy beats any in-place bit-shifting
approach for typical workloads.
Source§impl BitString
impl BitString
Source§impl BitString
impl BitString
Sourcepub fn replace_interval(&self, interval: UsizeCO, replacement: &Self) -> Self
pub fn replace_interval(&self, interval: UsizeCO, replacement: &Self) -> Self
Borrowing variant: returns a new BitString; self is unchanged.
Sourcepub fn replace_interval_assign(&mut self, interval: UsizeCO, replacement: &Self)
pub fn replace_interval_assign(&mut self, interval: UsizeCO, replacement: &Self)
Assigning variant: replaces the interval in-place.
When the replacement length equals the (clamped) interval length the operation is performed in-place without allocation. Otherwise a fresh buffer is allocated and swapped in.
Source§impl BitString
impl BitString
Source§impl BitString
impl BitString
Source§impl BitString
impl BitString
Sourcepub fn slice(&self, interval: UsizeCO) -> Self
pub fn slice(&self, interval: UsizeCO) -> Self
Returns a new BitString containing the bits in interval.
The interval is clamped to [0, self.bit_len()]. An interval that lies
entirely beyond the bit string returns an empty result.
Sourcepub fn slice_from(&self, start: usize) -> Self
pub fn slice_from(&self, start: usize) -> Self
Returns a new BitString containing bits from start to the end.
start is clamped to self.bit_len() — an out-of-bounds index returns
an empty result.
Sourcepub fn slice_until(&self, end: usize) -> Self
pub fn slice_until(&self, end: usize) -> Self
Returns a new BitString containing bits from the start to end.
end is clamped to self.bit_len() — a value beyond the bit string
returns all bits.
Source§impl BitString
impl BitString
pub fn matches_at(&self, index: usize, pattern: &Self) -> bool
pub fn starts_with(&self, prefix: &Self) -> bool
pub fn ends_with(&self, suffix: &Self) -> bool
Source§impl BitString
impl BitString
pub fn strip_prefix(&self, prefix: &Self) -> Option<Self>
pub fn strip_suffix(&self, suffix: &Self) -> Option<Self>
Trait Implementations§
impl Eq for BitString
Source§impl<'a> Extend<&'a bool> for BitString
impl<'a> Extend<&'a bool> for BitString
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a bool>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a bool>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Extend<bool> for BitString
impl Extend<bool> for BitString
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = bool>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = bool>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)