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

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 stored in this bit vector.

Returns true if this vector contains no bits.

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

Get the nth bit in this bit vector.

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.

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

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.