[][src]Struct bucket_vec::BucketVec

pub struct BucketVec<T, C = DefaultConfig> { /* fields omitted */ }

A vector-like data structure that never moves its contained elements.

This is solved by using internal fixed-capacity buckets instead of boxing all elements in isolation.

Formulas

Definitions

In the following we define

  • N := START_CAPACITY and
  • a := GROWTH_RATE

Bucket Capacity

For a != 1:

The total capacity of all buckets until bucket i (not including i) is expressed as:

capacity_until(i) := N * (a^i - 1) / (a-1)

The capacity of the ith bucket is then calculated by:

capacity(i) := floor(capacity_until(i+1)) - floor(capacity_until(i))

Where floor: f64 -> f64 rounds the f64 down to the next even f64 for positive f64.

Note that capacity(i) is approximately capacity(i)' := N * a^i.

For a == 1:

This case is trivial and all buckets are equally sized to have a capacity of N.

Accessing Elements by Index

Accessing the ith element of a BucketVec can be expressed by the following formulas:

For a != 1:

First we define the inverted capacity function for which 1 == capacity(i) * inv_capacity(i) forall i.

inv_capacity(i) = ceil(log(1 + (i + 1) * (a - 1) / N, a)) - 1

Where ceil: f64 -> f64 rounds the f64 up to the next even f64 for positive f64.

Having this the bucket_index and the entry_index inside the bucket indexed by bucket_index is expressed as:

bucket_index(i) = inv_capacity(i)
entry_index(i) = i - floor(capacity_until(bucket_index(i)))

For a == 1:

This case is very easy and we can simply calculate the bucket_index and entry_index by:

bucket_index(i) = i / N
entry_index(i) = i % N

Methods

impl<T, C> BucketVec<T, C>[src]

pub fn new() -> Self[src]

Creates a new empty bucket vector.

Note

This does not allocate any heap memory.

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

Returns the number of elements stored in the bucket vector.

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

Returns true if the bucket vector is empty.

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

Returns an iterator that yields shared references to the elements of the bucket vector.

Important traits for IterMut<'a, T>
pub fn iter_mut(&mut self) -> IterMut<T>[src]

Returns an iterator that yields exclusive reference to the elements of the bucket vector.

pub fn first(&self) -> Option<&T>[src]

Returns a shared reference to the first element of the bucket vector.

pub fn first_mut(&mut self) -> Option<&mut T>[src]

Returns an exclusive reference to the first element of the bucket vector.

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

Returns a shared reference to the last element of the bucket vector.

pub fn last_mut(&mut self) -> Option<&mut T>[src]

Returns an exclusive reference to the last element of the bucket vector.

impl<T, C> BucketVec<T, C> where
    C: BucketVecConfig
[src]

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

Returns a shared reference to the element at the given index if any.

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>[src]

Returns an exclusive reference to the element at the given index if any.

pub fn push(&mut self, new_value: T)[src]

Pushes a new element onto the bucket vector.

Note

This operation will never move other elements, reallocates or otherwise invalidate pointers of elements contained by the bucket vector.

pub fn push_get(&mut self, new_value: T) -> Access<T>[src]

Pushes a new element onto the bucket vector and returns access to it.

Note

This operation will never move other elements, reallocates or otherwise invalidate pointers of elements contained by the bucket vector.

Trait Implementations

impl<T, C> Clone for BucketVec<T, C> where
    T: Clone
[src]

impl<T: Debug, C: Debug> Debug for BucketVec<T, C>[src]

impl<T, C> Decode for BucketVec<T, C> where
    C: BucketVecConfig,
    T: Decode
[src]

impl<T> Default for BucketVec<T, DefaultConfig>[src]

impl<T, C> Encode for BucketVec<T, C> where
    T: Encode
[src]

impl<T, C> Eq for BucketVec<T, C> where
    T: Eq
[src]

impl<T, C> Extend<T> for BucketVec<T, C> where
    C: BucketVecConfig
[src]

impl<T, C> FromIterator<T> for BucketVec<T, C> where
    C: BucketVecConfig
[src]

impl<T, C> Hash for BucketVec<T, C> where
    T: Hash
[src]

impl<T, C> IntoIterator for BucketVec<T, C>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, T, C> IntoIterator for &'a BucketVec<T, C>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T, C> IntoIterator for &'a mut BucketVec<T, C>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T, C> Ord for BucketVec<T, C> where
    T: Ord
[src]

impl<T, C> PartialEq<BucketVec<T, C>> for BucketVec<T, C> where
    T: PartialEq
[src]

impl<T, C> PartialOrd<BucketVec<T, C>> for BucketVec<T, C> where
    T: PartialOrd
[src]

Auto Trait Implementations

impl<T, C> RefUnwindSafe for BucketVec<T, C> where
    T: RefUnwindSafe

impl<T, C> Send for BucketVec<T, C> where
    T: Send

impl<T, C> Sync for BucketVec<T, C> where
    T: Sync

impl<T, C> Unpin for BucketVec<T, C> where
    T: Unpin

impl<T, C> UnwindSafe for BucketVec<T, C> where
    T: UnwindSafe

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<S> Codec for S where
    S: Encode + Decode
[src]

impl<T, X> Decode for X where
    T: Decode + Into<X>,
    X: WrapperTypeDecode<Wrapped = T>, 
[src]

impl<T> DecodeAll for T where
    T: Decode
[src]

impl<T, X> Encode for X where
    T: Encode + ?Sized,
    X: WrapperTypeEncode<Target = T>, 
[src]

impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ mut T> for T where
    T: Encode
[src]

impl<T> EncodeLike<Arc<T>> for T where
    T: Encode
[src]

impl<T> EncodeLike<Box<T>> for T where
    T: Encode
[src]

impl<'a, T> EncodeLike<Cow<'a, T>> for T where
    T: Encode + ToOwned
[src]

impl<T> EncodeLike<Rc<T>> for T where
    T: Encode
[src]

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

impl<T, U> Into<U> for T where
    U: From<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> KeyedVec for T where
    T: Codec
[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.