Skip to main content

AppendVec

Struct AppendVec 

Source
pub struct AppendVec<T> { /* private fields */ }
Expand description

A thread-safe, append-only vector implementation with amortized O(1) push operations.

This data structure is optimized for concurrent append operations while maintaining strong memory safety guarantees. It uses a series of dynamically allocated buckets that grow exponentially in size to reduce allocation frequency.

Implementations§

Source§

impl<T> AppendVec<T>

Source

pub const fn new() -> Self

Creates a new, empty AppendVec.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new, empty AppendVec with a specified capacity.

This method pre-allocates buckets up to the specified capacity, reducing the number of reallocations as elements are added.

§Arguments
  • capacity - The initial capacity of the vector.
§Returns

A new AppendVec with the specified capacity.

Source

pub fn capacity(&self) -> usize

Returns the total capacity of the vector before reallocation would be needed.

Source

pub fn max_capacity(&self) -> usize

Returns the maximum capacity of the vector.

Source

pub fn clear(&mut self)

Clears the vector, dropping all elements and deallocating memory.

Source

pub fn iter(&self) -> AppendVecIter<'_, T>

Creates an iterator that yields references to individual elements.

Source

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

Get a reference to the element at the specified index, if it exists.

Source

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

Get a mutable reference to the element at the specified index, if it exists.

Source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Source

pub fn is_empty(&self) -> bool

Checks if the vector is empty.

Source

pub fn push(&self, item: T) -> usize

Pushes an item to the vector.

Source

pub fn grow_with(&self, size: usize, init: impl FnMut(usize) -> T) -> usize

Grows the vector to at least size elements, initializing new elements with the provided function.

This method ensures the vector contains at least size elements. If the current length is less than size, new elements are initialized by calling init with their index.

§Arguments
  • size - The minimum size the vector should have
  • init - A function that produces initial values for new elements, called with the index of each new element
§Returns

The previous length of the vector before growth

Source

pub fn grow_default(&self, size: usize) -> usize
where T: Default,

Grows the vector to at least size elements, initializing new elements with their default value.

This is a convenience method that calls grow_with using T::default() for new elements.

§Arguments
  • size - The minimum size the vector should have
§Returns

The previous length of the vector before growth

Source

pub fn grow(&self, size: usize, value: T) -> usize
where T: Clone,

Grows the vector to at least size elements, initializing new elements with the provided value.

This is a convenience method that calls grow_with using value.clone() for new elements.

§Arguments
  • size - The minimum size the vector should have
  • value - The value to initialize new elements with
§Returns

The previous length of the vector before growth

Source

pub fn extend( &self, items: impl IntoIterator<Item = T, IntoIter: ExactSizeIterator>, ) -> usize

Pushes multiple items at once when exclusive access is guaranteed.

§Panics

Panics if the reported iterator length would overflow the vector’s maximum capacity, or if the iterator yields a different number of items than reported by ExactSizeIterator::len. If it yields too few items, the reserved range is not published and the vector is left in a poisoned state, so subsequent insertions may stall. If it yields too many items, exactly the reported prefix is published before the panic and the vector remains usable.

Source

pub fn extend_unbounded(&mut self, items: impl IntoIterator<Item = T>) -> usize

Extends the vector with the given items, without any bounds checking.

This method is useful when you have exclusive access to the vector and want to extend it with an unknown iterator.

§Panics

Panics if a previous insertion panicked leaving the vector in a poisoned state.

Source

pub fn slice(&self, range: Range<usize>) -> AppendSlice<'_, T>

Returns a view over a contiguous range of elements.

The returned AppendSlice is a lightweight wrapper around several slice references, each coming from a different internal bucket. It offers the standard slice-like API (len, indexing, iteration) without copying the underlying data.

The function is lock-free and does not allocate.

§Panics

Panics if range.end is greater than the current length of the vector, or if range.start > range.end.

§Examples
use omp_core::append_vec::AppendVec;
let vec = AppendVec::with_capacity(10);
for i in 0..10 {
	vec.push(i);
}
let window = vec.slice(2..5);
assert_eq!(window.len(), 3);
assert_eq!(window[0], 2);
Source§

impl<T: Clone> AppendVec<T>

Source

pub fn to_vec(&self) -> Vec<T>

Creates a standard Vec from this AppendVec.

Trait Implementations§

Source§

impl<T: Clone> Clone for AppendVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for AppendVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for AppendVec<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for AppendVec<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> FromIterator<T> for AppendVec<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for AppendVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for AppendVec<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a AppendVec<T>

Implementation of IntoIterator for AppendVec

Source§

type IntoIter = AppendVecIter<'a, T>

Which kind of iterator are we turning this into?
Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Send> Send for AppendVec<T>

Source§

impl<T: Send + Sync> Sync for AppendVec<T>

Auto Trait Implementations§

§

impl<T> !Freeze for AppendVec<T>

§

impl<T> RefUnwindSafe for AppendVec<T>

§

impl<T> Unpin for AppendVec<T>

§

impl<T> UnsafeUnpin for AppendVec<T>

§

impl<T> UnwindSafe for AppendVec<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.