Struct primal_bit::BitVec
source · [−]pub struct BitVec { /* private fields */ }
Expand description
The bitvector type.
Implementations
sourceimpl BitVec
impl BitVec
pub fn from_u64s(data: Vec<u64>, bits: usize) -> BitVec
pub fn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_u64s(&self) -> &[u64]
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.
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);
}
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);
pub unsafe fn set_unchecked(&mut self, i: usize, x: bool)
sourcepub fn set_all(&mut self)
pub fn set_all(&mut self)
Sets all bits to 1.
Examples
ⓘ
use std::collections::BitVec;
let before = 0b01100000;
let after = 0b11111111;
let mut bv = BitVec::from_bytes(&[before]);
bv.set_all();
assert_eq!(bv, BitVec::from_bytes(&[after]));
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);
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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more