Struct smallbitvec::SmallBitVec [−][src]
pub struct SmallBitVec { /* fields omitted */ }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
Create an empty vector.
Create a vector containing len bits, each set to val.
Create an empty vector with enough storage pre-allocated to store at least cap bits
without resizing.
The number of bits that can be stored in this bit vector without re-allocating.
Get the nth bit in this bit vector, without bounds checks.
Set the nth bit in this bit vector to val. Panics if the index is out of bounds.
Set the nth bit in this bit vector to val, without bounds checks.
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));
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);
Remove and return the bit at index idx, shifting all later bits toward the front.
Panics if the index is out of bounds.
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.
Returns an iterator that yields the bits of the vector in order, as bool values.
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);
Returns true if all the bits in the vec are set to zero/false.
On an empty vector, returns true.
Returns true if all the bits in the vec are set to one/true.
On an empty vector, returns true.
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.
Resizes the vector so that its length is equal to len.
If len is less than the current length, the vector simply truncated.
If len is greater than the current length, value is appended to the
vector until its length equals len.
If the vector owns a heap allocation, returns a pointer to the start of the allocation.
The layout of the data at this allocation is a private implementation detail.
Converts this SmallBitVec into its internal representation.
The layout of the data inside both enum variants is a private implementation detail.
Creates a SmallBitVec directly from the internal storage of another
SmallBitVec.
Safety
This is highly unsafe. storage needs to have been previously generated
via SmallBitVec::into_storage (at least, it’s highly likely to be
incorrect if it wasn’t.) Violating this may cause problems like corrupting the
allocator’s internal data structures.
Examples
fn main() { let v = SmallBitVec::from_elem(200, false); // Get the internal representation of the SmallBitVec. // unless we transfer its ownership somewhere else. let storage = v.into_storage(); /// Make a copy of the SmallBitVec's data. let cloned_storage = match storage { InternalStorage::Spilled(vs) => InternalStorage::Spilled(vs.clone()), inline => inline, }; /// Create a new SmallBitVec from the coped storage. let v = unsafe { SmallBitVec::from_storage(cloned_storage) }; }
Trait Implementations
Extends a collection with the contents of an iterator. Read more
extend_one)Extends a collection with exactly one element.
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
Auto Trait Implementations
impl RefUnwindSafe for SmallBitVec
impl Send for SmallBitVec
impl Sync for SmallBitVec
impl Unpin for SmallBitVec
impl UnwindSafe for SmallBitVec
Blanket Implementations
Mutably borrows from an owned value. Read more