pub struct VecBelt<T> { /* private fields */ }Expand description
A high-performant, concurrent, lock-free data structure suitable for multi-threaded
bulk-appending (takes a &self) and single-threaded consuming (takes a &mut self).
See the module-level documentation for more details.
Implementations§
Source§impl<T> VecBelt<T>
impl<T> VecBelt<T>
Sourcepub fn new(initial_size: usize) -> Self
pub fn new(initial_size: usize) -> Self
Creates a new VecBelt<T>, preallocating a fragment of the given initial size.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Reads the length of the vector atomically. Prefer len_mut if possible.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Tests whether the vector is empty atomically. Prefer is_empty_mut if
possible.
Sourcepub fn len_mut(&mut self) -> usize
pub fn len_mut(&mut self) -> usize
Reads the length of the vector non-atomically via &mut self.
Sourcepub fn is_empty_mut(&mut self) -> bool
pub fn is_empty_mut(&mut self) -> bool
Tests whether the vector is empty non-atomically via &mut self.
Sourcepub unsafe fn append_raw(
&self,
additional: usize,
acceptor: impl FnOnce(*mut T),
) -> usize
pub unsafe fn append_raw( &self, additional: usize, acceptor: impl FnOnce(*mut T), ) -> usize
Extends the vector by additional elements, invoking a closure with an uninitialized slice
to it and the starting element’s absolute index in the vector.
§Safety
additionalmust be less or equal toisize::MAX.acceptormust fully initialize and not read the given pointer foradditionalconsecutive items. Notably, this meanspanic!(..)-ing mid-way will lead to undefined behavior due to uninitialized elements present.
Sourcepub fn append(&self, transfer: impl Transfer<T>) -> usize
pub fn append(&self, transfer: impl Transfer<T>) -> usize
Appends a slice to this vector, returning the absolute index of the first element.
Sourcepub fn clear<'a, R>(
&'a mut self,
consumer: impl FnOnce(ConsumeSlice<'a, T>) -> R,
) -> R
pub fn clear<'a, R>( &'a mut self, consumer: impl FnOnce(ConsumeSlice<'a, T>) -> R, ) -> R
Flattens the vector (if it isn’t flattened already), invokes a closure with an owned slice, and clears the vector.
Trait Implementations§
impl<T> RefUnwindSafe for VecBelt<T>
impl<T: Send> Send for VecBelt<T>
§Safety
VecBelt<T> provides synchronization primitives that won’t lead to data races.
impl<T: Send> Sync for VecBelt<T>
§Safety
T: Sync isn’t necessary here, because there is guaranteed not to be references to the same
elements across threads.