pub struct BitVector { /* private fields */ }Expand description
Implementations§
Source§impl BitVector
impl BitVector
Sourcepub fn with_capacity(bits: usize) -> Self
pub fn with_capacity(bits: usize) -> Self
Creates a bit vector with the specified capacity (in bits).
Sourcepub fn from_bools(bools: &[bool]) -> Self
pub fn from_bools(bools: &[bool]) -> Self
Creates a bit vector from a slice of booleans.
Sourcepub fn filled(len: usize, value: bool) -> Self
pub fn filled(len: usize, value: bool) -> Self
Creates a bit vector with all bits set to the same value.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Returns the number of bits set to true.
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Returns the number of bits set to false.
Sourcepub fn to_bools(&self) -> Vec<bool>
pub fn to_bools(&self) -> Vec<bool>
Converts back to a Vec<bool>.
§Panics
Panics if an internal index is out of bounds (invariant violation).
Sourcepub fn iter(&self) -> impl Iterator<Item = bool> + '_
pub fn iter(&self) -> impl Iterator<Item = bool> + '_
Returns an iterator over the bits.
§Panics
Panics if an internal index is out of bounds (invariant violation).
Sourcepub fn ones_iter(&self) -> impl Iterator<Item = usize> + '_
pub fn ones_iter(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over indices where bits are true.
§Panics
Panics if an internal index is out of bounds (invariant violation).
Sourcepub fn zeros_iter(&self) -> impl Iterator<Item = usize> + '_
pub fn zeros_iter(&self) -> impl Iterator<Item = usize> + '_
Returns an iterator over indices where bits are false.
§Panics
Panics if an internal index is out of bounds (invariant violation).
Sourcepub fn compression_ratio(&self) -> f64
pub fn compression_ratio(&self) -> f64
Returns the compression ratio (original bytes / compressed bytes).
Sourcepub fn and(&self, other: &Self) -> Self
pub fn and(&self, other: &Self) -> Self
Performs bitwise AND with another bit vector.
The result has the length of the shorter vector.
Sourcepub fn or(&self, other: &Self) -> Self
pub fn or(&self, other: &Self) -> Self
Performs bitwise OR with another bit vector.
The result has the length of the shorter vector.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserializes from bytes.
§Errors
Returns Err if the byte slice is too short or contains invalid data.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BitVector
impl<'de> Deserialize<'de> for BitVector
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl FromIterator<bool> for BitVector
impl FromIterator<bool> for BitVector
impl Eq for BitVector
impl StructuralPartialEq for BitVector
Auto Trait Implementations§
impl Freeze for BitVector
impl RefUnwindSafe for BitVector
impl Send for BitVector
impl Sync for BitVector
impl Unpin for BitVector
impl UnsafeUnpin for BitVector
impl UnwindSafe for BitVector
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more