Struct smallbitvec::SmallBitVec
source · pub struct SmallBitVec { /* private fields */ }Expand description
A resizable bit vector, optimized for size and inline storage.
SmallBitVec is exactly one word wide. Depending on the required capacity, this word
either stores the bits inline, or it stores a pointer to a separate buffer on the heap.
Implementations
sourceimpl SmallBitVec
impl SmallBitVec
sourcepub fn new() -> SmallBitVec
pub fn new() -> SmallBitVec
Create an empty vector.
sourcepub fn from_elem(len: usize, val: bool) -> SmallBitVec
pub fn from_elem(len: usize, val: bool) -> SmallBitVec
Create a vector containing len bits, each set to val.
sourcepub fn with_capacity(cap: usize) -> SmallBitVec
pub fn with_capacity(cap: usize) -> SmallBitVec
Create an empty vector with enough storage pre-allocated to store at least cap bits
without resizing.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
The number of bits that can be stored in this bit vector without re-allocating.
sourcepub unsafe fn get_unchecked(&self, n: usize) -> bool
pub unsafe fn get_unchecked(&self, n: usize) -> bool
Get the nth bit in this bit vector, without bounds checks.
sourcepub fn set(&mut self, n: usize, val: bool)
pub fn set(&mut self, n: usize, val: bool)
Set the nth bit in this bit vector to val. Panics if the index is out of bounds.
sourcepub unsafe fn set_unchecked(&mut self, n: usize, val: bool)
pub unsafe fn set_unchecked(&mut self, n: usize, val: bool)
Set the nth bit in this bit vector to val, without bounds checks.
sourcepub fn push(&mut self, val: bool)
pub fn push(&mut self, val: bool)
Append a bit to the end of the vector.
use smallbitvec::SmallBitVec;
let mut v = SmallBitVec::new();
v.push(true);
assert_eq!(v.len(), 1);
assert_eq!(v.get(0), Some(true));sourcepub fn pop(&mut self) -> Option<bool>
pub fn pop(&mut self) -> Option<bool>
Remove the last bit from the vector and return it, if there is one.
use smallbitvec::SmallBitVec;
let mut v = SmallBitVec::new();
v.push(false);
assert_eq!(v.pop(), Some(false));
assert_eq!(v.len(), 0);
assert_eq!(v.pop(), None);sourcepub fn remove(&mut self, idx: usize) -> bool
pub fn remove(&mut self, idx: usize) -> bool
Remove and return the bit at index idx, shifting all later bits toward the front.
Panics if the index is out of bounds.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve capacity for at least additional more elements to be inserted.
May reserve more space than requested, to avoid frequent reallocations.
Panics if the new capacity overflows usize.
Re-allocates only if self.capacity() < self.len() + additional.
sourcepub fn iter(&self) -> Iter<'_>ⓘ
pub fn iter(&self) -> Iter<'_>ⓘ
Returns an iterator that yields the bits of the vector in order, as bool values.
sourcepub fn range(&self, range: Range<usize>) -> VecRange<'_>
pub fn range(&self, range: Range<usize>) -> VecRange<'_>
Returns an immutable view of a range of bits from this vec.
#[macro_use] extern crate smallbitvec;
let v = sbvec![true, false, true];
let r = v.range(1..3);
assert_eq!(r[1], true);sourcepub fn all_false(&self) -> bool
pub fn all_false(&self) -> bool
Returns true if all the bits in the vec are set to zero/false.
On an empty vector, returns true.
sourcepub fn all_true(&self) -> bool
pub fn all_true(&self) -> bool
Returns true if all the bits in the vec are set to one/true.
On an empty vector, returns true.
sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shorten the vector, keeping the first len elements and dropping the rest.
If len is greater than or equal to the vector’s current length, this has no
effect.
This does not re-allocate.
Trait Implementations
sourceimpl Clone for SmallBitVec
impl Clone for SmallBitVec
sourceimpl Debug for SmallBitVec
impl Debug for SmallBitVec
sourceimpl Default for SmallBitVec
impl Default for SmallBitVec
sourceimpl Drop for SmallBitVec
impl Drop for SmallBitVec
sourceimpl Extend<bool> for SmallBitVec
impl Extend<bool> for SmallBitVec
sourcefn extend<I: IntoIterator<Item = bool>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = bool>>(&mut self, iter: I)
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)