Struct yabf::SmallYabf[][src]

pub struct SmallYabf { /* fields omitted */ }

Yet another bit field implementation. This is a simple, small and hopefully efficient bit field implementation. It uses SmallVec as an internal container. The first 128 bits will be stored on the stack.

It is intended for cases where a program iterates over list or other usize indexed containers and simple bit based bookkeeping is required.

Implementations

impl SmallYabf[src]

pub fn with_capacity(bits: usize) -> Self[src]

Construct an empty bit field with enough capacity pre-allocated to store at least n bits.

Will create a heap allocation only if n is larger than the inline capacity of the internal SmallVec.


let bf = SmallYabf::with_capacity(100);

assert!(bf.is_empty());
assert!(bf.capacity() >= 100);

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

Returns the value of the ‘n’:th bit in the bit field.


let mut bf = SmallYabf::default();

assert!(bf.is_empty());
assert!(!bf.bit(10));
bf.set_bit(10,true);
assert!(bf.bit(10));

pub fn set_bit(&mut self, n: usize, state: bool)[src]

Sets the ‘n’:th bit in the bit field. If the bit field capacity is not large enough more space will be allocated.


let mut bf = SmallYabf::default();

assert!(bf.is_empty());
assert!(!bf.bit(10));
bf.set_bit(10,true);
assert!(bf.bit(10));

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

Returns true if all bits are set to false

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

The number of bits the bit field can hold without reallocating

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

The len() of the internal vector

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

Reserve capacity for additional_bits more bits to be inserted.

May reserve more space to avoid frequent re-allocations.

Panics if the capacity computation overflows usize.

pub fn clear(&mut self)[src]

Remove all elements from the vector. This method simply delegates clear() to the underlying vector std::vec::Vec or smallvec::SmallVec. So what actually happen depends on the feature set.

Trait Implementations

impl BitOrAssign<&'_ SmallYabf> for SmallYabf[src]

bit or assign operation This is a relatively expensive O(size of container) operation.


let mut a = SmallYabf::default();
let mut b = SmallYabf::default();
a.set_bit(45,true);
b.set_bit(12345,true);
assert!(!a.bit(12345));
assert!(a.bit(45));
a |= &b;
assert!(a.bit(12345));
assert!(a.bit(45));

impl Clone for SmallYabf[src]

impl Debug for SmallYabf[src]

impl Default for SmallYabf[src]

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

type Item = usize

The type of the elements being iterated over.

type IntoIter = SmallYabfIterator<'a>

Which kind of iterator are we turning this into?

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.