Struct primal_bit::BitVec
source · [−]pub struct BitVec { /* private fields */ }
Expand description
The bitvector type.
Implementations
sourceimpl BitVec
impl BitVec
sourcepub fn from_bytes(data: Vec<u8>, nbits: usize) -> BitVec
pub fn from_bytes(data: Vec<u8>, nbits: usize) -> BitVec
Creates a BitVec
from the given bytes.
sourcepub fn from_elem(nbits: usize, bit: bool) -> BitVec
pub fn from_elem(nbits: usize, bit: bool) -> BitVec
Creates a BitVec
that holds nbits
elements, setting each element
to bit
.
Examples
ⓘ
use std::collections::BitVec;
let mut bv = BitVec::from_elem(10, false);
assert_eq!(bv.len(), 10);
for x in bv.iter() {
assert_eq!(x, false);
}
pub fn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourcepub fn get(&self, i: usize) -> Option<bool>
pub fn get(&self, i: usize) -> Option<bool>
Retrieves the value at index i
, or None
if the index is out of bounds.
Examples
ⓘ
use std::collections::BitVec;
let bv = BitVec::from_bytes(&[0b01100000]);
assert_eq!(bv.get(0), Some(false));
assert_eq!(bv.get(1), Some(true));
assert_eq!(bv.get(100), None);
// Can also use array indexing
assert_eq!(bv[1], true);
sourceimpl BitVec
impl BitVec
sourcepub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = bool;
pub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = bool;
Returns an iterator over the elements of the vector in order.
Examples
ⓘ
use std::collections::BitVec;
let bv = BitVec::from_bytes(&[0b01110100, 0b10010010]);
assert_eq!(bv.iter().filter(|x| *x).count(), 7);
sourceimpl BitVec
impl BitVec
sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Count the number of ones in the entire BitVec
.
sourcepub fn count_ones_before(&self, bit: usize) -> usize
pub fn count_ones_before(&self, bit: usize) -> usize
Count the number of ones for the bits up to but not including
the bit
th bit.
sourcepub fn find_nth_bit(&self, n: usize) -> Option<usize>
pub fn find_nth_bit(&self, n: usize) -> Option<usize>
Find the index of the n
th (0-indexed) set bit.
Trait Implementations
sourceimpl<'a> IntoIterator for &'a BitVec
impl<'a> IntoIterator for &'a BitVec
impl Eq for BitVec
Auto Trait Implementations
impl RefUnwindSafe for BitVec
impl Send for BitVec
impl Sync for BitVec
impl Unpin for BitVec
impl UnwindSafe for BitVec
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more