pub struct AppendOnlyVec<T, const AMOUNT_OF_BINS: usize = 32, const BIN_OFFSET: u32 = 3> { /* private fields */ }Expand description
Append only vec of items T.
This vec will never re-allocate and never remove items. This means that as long as this vec is around, we can have valid references to all the data it stores. This also means that we can add items to the vec without having a mutable reference to it.
This vec has a fixed maximum capacity as configured by the const generic
parameters. Calling Self::push after that capacity is exhausted will panic.
AMOUNT_OF_BINS is total amount of item bins (=arrays). Each bin has double the capacity then the one before, so even with a low number here, we should be able to store a huge amount of items.
BIN_OFFSET calculates the offset of the first bin. Effectively this mean our first bin will have 2^BIN_OFFSET size.
Implementations§
Source§impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new AppendOnlyVec of T items
use rama_utils::collections::AppendOnlyVec;
// This should fail because this overflow INITIAL_BIN_SIZE
_ = AppendOnlyVec::<usize, 300, 100>::new();use rama_utils::collections::AppendOnlyVec;
// This should fail because the total size exceeds isize::MAX
_ = AppendOnlyVec::<u64, 60, 10>::new();Sourcepub fn push(&self, element: T) -> usize
pub fn push(&self, element: T) -> usize
Pushes an element and returns its index.
§Panics
Panics when the fixed maximum capacity is exceeded.
Use Self::capacity to inspect the configured limit.
pub fn get(&self, idx: usize) -> Option<&T>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub const fn capacity() -> usize
pub const fn capacity() -> usize
Returns the maximum number of elements this configuration can hold. Total capacity = initial_bin_size * (2^AMOUNT_OF_BINS - 1)
Sourcepub fn iter(&self) -> Iter<'_, T, AMOUNT_OF_BINS, BIN_OFFSET> ⓘ
pub fn iter(&self) -> Iter<'_, T, AMOUNT_OF_BINS, BIN_OFFSET> ⓘ
Returns an iterator over the elements currently in the vector. The iterator snapshots the length at creation time.
Sourcepub unsafe fn get_unchecked(&self, idx: usize) -> &T
pub unsafe fn get_unchecked(&self, idx: usize) -> &T
Trait Implementations§
Source§impl<T: Debug, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Debug for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
impl<T: Debug, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Debug for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
Source§impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Default for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Default for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
Source§impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Drop for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
impl<T, const AMOUNT_OF_BINS: usize, const BIN_OFFSET: u32> Drop for AppendOnlyVec<T, AMOUNT_OF_BINS, BIN_OFFSET>
Source§impl<T, const BINS: usize, const OFFSET: u32> Extend<T> for AppendOnlyVec<T, BINS, OFFSET>
impl<T, const BINS: usize, const OFFSET: u32> Extend<T> for AppendOnlyVec<T, BINS, OFFSET>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, const BINS: usize, const OFFSET: u32> Extend<T> for &AppendOnlyVec<T, BINS, OFFSET>
impl<T, const BINS: usize, const OFFSET: u32> Extend<T> for &AppendOnlyVec<T, BINS, OFFSET>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)