Struct primal_bit::BitVec
[−]
[src]
pub struct BitVec { /* fields omitted */ }
The bitvector type.
Methods
impl BitVec
[src]
fn new() -> BitVec
fn from_u64s(data: Vec<u64>, bits: usize) -> BitVec
fn as_bytes_mut(&mut self) -> &mut [u8]
fn as_bytes(&self) -> &[u8]
fn as_u64s(&self) -> &[u64]
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.
fn find_nth_bit(&self, n: usize) -> Option<usize>
Find the index of the n
th (0-indexed) set bit.
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); }
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);
fn set(&mut self, i: usize, x: bool)
Sets the value of a bit at an index i
.
Panics
Panics if i
is out of bounds.
Examples
use std::collections::BitVec; let mut bv = BitVec::from_elem(5, false); bv.set(3, true); assert_eq!(bv[3], true);
unsafe fn set_unchecked(&mut self, i: usize, x: bool)
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]));
fn iter(&self) -> Iter
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);
fn len(&self) -> usize
Returns the total number of bits in this vector
fn is_empty(&self) -> bool
Returns true if there are no bits in this vector
fn clear(&mut self)
Clears all bits in this vector.
Trait Implementations
impl Index<usize> for BitVec
[src]
type Output = bool
The returned type after indexing
fn index(&self, i: usize) -> &bool
The method for the indexing (container[index]
) operation
impl Default for BitVec
[src]
impl Clone for BitVec
[src]
fn clone(&self) -> BitVec
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &BitVec)
Performs copy-assignment from source
. Read more
impl Debug for BitVec
[src]
impl Hash for BitVec
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for BitVec
[src]
fn eq(&self, other: &BitVec) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.