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>
impl<T> AppendVec<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total capacity of the vector before reallocation would be needed.
Sourcepub fn max_capacity(&self) -> usize
pub fn max_capacity(&self) -> usize
Returns the maximum capacity of the vector.
Sourcepub fn iter(&self) -> AppendVecIter<'_, T> ⓘ
pub fn iter(&self) -> AppendVecIter<'_, T> ⓘ
Creates an iterator that yields references to individual elements.
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Get a reference to the element at the specified index, if it exists.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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.
Sourcepub fn grow_with(&self, size: usize, init: impl FnMut(usize) -> T) -> usize
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 haveinit- 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
Sourcepub fn grow_default(&self, size: usize) -> usizewhere
T: Default,
pub fn grow_default(&self, size: usize) -> usizewhere
T: Default,
Sourcepub fn grow(&self, size: usize, value: T) -> usizewhere
T: Clone,
pub fn grow(&self, size: usize, value: T) -> usizewhere
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 havevalue- The value to initialize new elements with
§Returns
The previous length of the vector before growth
Sourcepub fn extend(
&self,
items: impl IntoIterator<Item = T, IntoIter: ExactSizeIterator>,
) -> usize
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.
Sourcepub fn extend_unbounded(&mut self, items: impl IntoIterator<Item = T>) -> usize
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.
Sourcepub fn slice(&self, range: Range<usize>) -> AppendSlice<'_, T>
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);Trait Implementations§
Source§impl<T> FromIterator<T> for AppendVec<T>
impl<T> FromIterator<T> for AppendVec<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Source§impl<'a, T> IntoIterator for &'a AppendVec<T>
Implementation of IntoIterator for AppendVec
impl<'a, T> IntoIterator for &'a AppendVec<T>
Implementation of IntoIterator for AppendVec
impl<T: Send> Send for AppendVec<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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