pub struct BitSpan<'a, T: BitWord> { /* private fields */ }
Expand description
A non-owning read-only view into a bit array.
BitSpan
provides a view into a sequence of bits stored in memory, allowing
read-only access to individual bits or ranges of bits. It can be used to
efficiently operate on a subset of bits without copying or allocating memory.
The span is defined by:
- A pointer to the start of the word array
- A bit offset from the start of the first word
- A length in bits
§Safety
This type uses raw pointers internally. The caller must ensure that:
- The referenced memory remains valid for the lifetime of the span
- The offset and length parameters don’t cause out-of-bounds access
Implementations§
Source§impl<'a, T: BitWord> BitSpan<'a, T>
impl<'a, T: BitWord> BitSpan<'a, T>
Sourcepub fn from_raw_parts(ptr: *const T, offset: usize, len: usize) -> Self
pub fn from_raw_parts(ptr: *const T, offset: usize, len: usize) -> Self
Creates a new BitSpan
from raw parts.
This function allows creating a span directly from a raw pointer, which is useful for interfacing with external memory or creating views into existing bit arrays.
§Arguments
ptr
- A pointer to the word array (will be converted to non-null)offset
- The bit offset from the start of the first wordlen
- The number of bits in the span
§Safety
The caller must ensure that:
- The pointer is valid for reads of
len
bits starting atoffset
- The memory remains valid for the lifetime of the returned span
If ptr
is null, a dangling pointer will be used. This is safe as long
as len
is 0, but will lead to undefined behavior otherwise.
Trait Implementations§
Source§impl<'a, 'b, T: BitWord> BitAndAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
impl<'a, 'b, T: BitWord> BitAndAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
Source§fn bitand_assign(&mut self, rhs: &'b BitSpan<'b, T>)
fn bitand_assign(&mut self, rhs: &'b BitSpan<'b, T>)
&=
operation. Read moreSource§impl<'a, 'b, T: BitWord> BitOrAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
impl<'a, 'b, T: BitWord> BitOrAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
Source§fn bitor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
fn bitor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
|=
operation. Read moreSource§impl<'a, T: BitWord> BitRead for BitSpan<'a, T>
impl<'a, T: BitWord> BitRead for BitSpan<'a, T>
Source§type Iter<'b> = BitSpanIter<'b, T>
where
Self: 'b
type Iter<'b> = BitSpanIter<'b, T> where Self: 'b
The iterator type returned by the iter
method.
Source§fn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns true if the span is empty or contains no set bits.
This implementation considers a span empty if either:
- It has zero length
- It has no bits set to 1
Source§fn count_ones(&self) -> usize
fn count_ones(&self) -> usize
Source§fn all(&self) -> bool
fn all(&self) -> bool
Returns true if all bits in the span are set to 1.
§Returns
true
if the span is non-empty and all bits are set to 1,
false
otherwise
Source§fn any(&self) -> bool
fn any(&self) -> bool
Returns true if any bit in the span is set to 1.
§Returns
true
if at least one bit is set to 1, false
otherwise
Source§fn iter(&self) -> Self::Iter<'_>
fn iter(&self) -> Self::Iter<'_>
Returns an iterator over the indices of bits set to 1.
§Returns
An iterator that yields the indices of all bits set to 1 in ascending order
fn none(&self) -> bool
Source§impl<'a, 'b, T: BitWord> BitXorAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
impl<'a, 'b, T: BitWord> BitXorAssign<&'b BitSpan<'b, T>> for BitSpanMut<'a, T>
Source§fn bitxor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
fn bitxor_assign(&mut self, rhs: &'b BitSpan<'b, T>)
^=
operation. Read more