pub struct BitVector { /* private fields */ }Implementations§
source§impl BitVector
impl BitVector
sourcepub fn with_capacity(n_bits: usize) -> Self
pub fn with_capacity(n_bits: usize) -> Self
Creates an empty binary vector with at least a capacity of n_bits.
sourcepub fn with_zeros(n_bits: usize) -> Self
pub fn with_zeros(n_bits: usize) -> Self
Creates a binary vector with n_bits set to 0.
sourcepub fn push(&mut self, bit: bool)
pub fn push(&mut self, bit: bool)
Pushes a bit at the end of the binary vector.
Example
use qwt::{BitVector, AccessBin};
let mut bv = BitVector::new();
bv.push(true);
bv.push(false);
bv.push(true);
assert_eq!(bv.len(), 3);
assert_eq!(bv.get(0), Some(true));sourcepub fn append_bits(&mut self, bits: u64, len: usize)
pub fn append_bits(&mut self, bits: u64, len: usize)
Appends len bits at the end of the bit vector by taking
the least significant len bits in the u64 value bits.
Panics
Panics if len is larger than 64 or if a bit of position
larger than len is set in bits.
Examples
use qwt::BitVector;
let mut bv = BitVector::new();
bv.append_bits(5, 3); // appends 101
bv.append_bits(6, 4); // appends 0110
assert_eq!(bv.len(), 7);
assert_eq!(bv.get_bits(0, 3), Some(5));sourcepub fn extend_with_zeros(&mut self, n: usize)
pub fn extend_with_zeros(&mut self, n: usize)
Extends the bit vector by adding n bits set to 0.
Examples
use qwt::{BitVector, AccessBin};
let mut bv = BitVector::new();
bv.extend_with_zeros(10);
assert_eq!(bv.len(), 10);
assert_eq!(bv.get(8), Some(false));sourcepub fn get_bits(&self, index: usize, len: usize) -> Option<u64>
pub fn get_bits(&self, index: usize, len: usize) -> Option<u64>
Accesses len bits, with 1 <= len <= 64,
starting at position index.
Returns None if index+len is out of bounds or
len == 0 or len > 64.
sourcepub fn set_bits(&mut self, index: usize, len: usize, bits: u64)
pub fn set_bits(&mut self, index: usize, len: usize, bits: u64)
Sets len bits, with 1 <= len <= 64,
starting at position index to the len least
significant bits in bits.
Panics
Panics if index+len is out of bounds or
len > 64 or if most significant bit in bits
ia at a position larger than of equal to len.
sourcepub fn ones(&self) -> BitVectorBitPositionsIter<'_, true> ⓘ
pub fn ones(&self) -> BitVectorBitPositionsIter<'_, true> ⓘ
Returns an iterator over positions of bit set to 1 in the bit vector.
Examples
use qwt::BitVector;
let vv: Vec<usize> = vec![0, 63, 128, 129, 254, 1026];
let bv: BitVector = vv.iter().copied().collect();
let v: Vec<usize> = bv.ones().collect();
assert_eq!(v, vv);sourcepub fn zeros(&self) -> BitVectorBitPositionsIter<'_, false> ⓘ
pub fn zeros(&self) -> BitVectorBitPositionsIter<'_, false> ⓘ
Gives an iterator over positions of bit set to 0 in the bit vector.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the underlying vector of 64bit words to fit.
sourcepub fn iter(&self) -> BitVectorIter<'_> ⓘ
pub fn iter(&self) -> BitVectorIter<'_> ⓘ
Returns a non-consuming iterator over bits of the bit vector.
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 Extend<bool> for BitVector
impl Extend<bool> for BitVector
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = bool>,
fn extend<T>(&mut self, iter: T)where
T: 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)source§impl Extend<usize> for BitVector
impl Extend<usize> for BitVector
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = usize>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = usize>,
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 FromIterator<bool> for BitVector
impl FromIterator<bool> for BitVector
source§impl FromIterator<usize> for BitVector
impl FromIterator<usize> for BitVector
source§impl<'a> IntoIterator for &'a BitVector
impl<'a> IntoIterator for &'a BitVector
source§impl IntoIterator for BitVector
impl IntoIterator for BitVector
source§impl PartialEq for BitVector
impl PartialEq for BitVector
source§impl SpaceUsage for BitVector
impl SpaceUsage for BitVector
source§fn space_usage_byte(&self) -> usize
fn space_usage_byte(&self) -> usize
Returns the space usage in bytes.