Struct primal_bit::BitVec
source · pub struct BitVec { /* private fields */ }
Expand description
The bitvector type.
Implementations§
source§impl 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.
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes(&self) -> &[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);
source§impl 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§
source§impl<'a> IntoIterator for &'a BitVec
impl<'a> IntoIterator for &'a BitVec
source§impl PartialEq for BitVec
impl PartialEq for BitVec
impl Eq for BitVec
Auto Trait Implementations§
impl Freeze for BitVec
impl RefUnwindSafe for BitVec
impl Send for BitVec
impl Sync for BitVec
impl Unpin for BitVec
impl UnwindSafe for BitVec
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
Mutably borrows from an owned value. Read more