[][src]Struct smallbitvec::SmallBitVec

pub struct SmallBitVec { /* fields omitted */ }

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.

Methods

impl SmallBitVec[src]

pub fn new() -> SmallBitVec[src]

Create an empty vector.

pub fn from_elem(len: usize, val: bool) -> SmallBitVec[src]

Create a vector containing len bits, each set to val.

pub fn with_capacity(cap: usize) -> SmallBitVec[src]

Create an empty vector with enough storage pre-allocated to store at least cap bits without resizing.

pub fn len(&self) -> usize[src]

The number of bits stored in this bit vector.

pub fn is_empty(&self) -> bool[src]

Returns true if this vector contains no bits.

pub fn capacity(&self) -> usize[src]

The number of bits that can be stored in this bit vector without re-allocating.

pub fn get(&self, n: usize) -> Option<bool>[src]

Get the nth bit in this bit vector.

pub fn last(&self) -> Option<bool>[src]

Get the last bit in this bit vector.

pub unsafe fn get_unchecked(&self, n: usize) -> bool[src]

Get the nth bit in this bit vector, without bounds checks.

pub fn set(&mut self, n: usize, val: bool)[src]

Set the nth bit in this bit vector to val. Panics if the index is out of bounds.

pub unsafe fn set_unchecked(&mut self, n: usize, val: bool)[src]

Set the nth bit in this bit vector to val, without bounds checks.

pub fn push(&mut self, val: bool)[src]

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));

pub fn pop(&mut self) -> Option<bool>[src]

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);

pub fn remove(&mut self, idx: usize) -> bool[src]

Remove and return the bit at index idx, shifting all later bits toward the front.

Panics if the index is out of bounds.

pub fn clear(&mut self)[src]

Remove all elements from the vector, without deallocating its buffer.

pub fn reserve(&mut self, additional: usize)[src]

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.

Important traits for Iter<'a>
pub fn iter(&self) -> Iter[src]

Returns an iterator that yields the bits of the vector in order, as bool values.

pub fn range(&self, range: Range<usize>) -> VecRange[src]

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);

pub fn all_false(&self) -> bool[src]

Returns true if all the bits in the vec are set to zero/false.

On an empty vector, returns true.

pub fn all_true(&self) -> bool[src]

Returns true if all the bits in the vec are set to one/true.

On an empty vector, returns true.

pub fn truncate(&mut self, len: usize)[src]

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.

pub fn resize(&mut self, len: usize, value: bool)[src]

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.

pub fn heap_ptr(&self) -> Option<*const usize>[src]

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.

pub fn into_storage(self) -> InternalStorage[src]

Converts this SmallBitVec into its internal representation.

The layout of the data inside both enum variants is a private implementation detail.

pub unsafe fn from_storage(storage: InternalStorage) -> SmallBitVec[src]

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

impl PartialEq<SmallBitVec> for SmallBitVec[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl IntoIterator for SmallBitVec[src]

type Item = bool

The type of the elements being iterated over.

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a SmallBitVec[src]

type Item = bool

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

impl Clone for SmallBitVec[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Extend<bool> for SmallBitVec[src]

impl Eq for SmallBitVec[src]

impl Drop for SmallBitVec[src]

impl Default for SmallBitVec[src]

impl Debug for SmallBitVec[src]

impl Hash for SmallBitVec[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Index<usize> for SmallBitVec[src]

type Output = bool

The returned type after indexing.

impl FromIterator<bool> for SmallBitVec[src]

Auto Trait Implementations

impl Send for SmallBitVec

impl Sync for SmallBitVec

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]