pub struct LocalRingBuffer<T> { /* private fields */ }Expand description
Single-threaded ring buffer optimized for maximum performance
LocalRingBuffer uses VecDeque directly without synchronization primitives,
providing optimal performance for single-threaded contexts.
For multi-threaded scenarios requiring concurrent access, use the thread-safe
RingBuffer type (defined below in this module) which wraps the buffer in
Arc<RwLock> for safe concurrent access.
Implementations§
Source§impl<T: Copy + Default> LocalRingBuffer<T>
impl<T: Copy + Default> LocalRingBuffer<T>
Sourcepub fn sliding_window(&self, size: usize) -> Vec<T>
pub fn sliding_window(&self, size: usize) -> Vec<T>
Get sliding window of last N elements
§Performance
Efficiently accesses the last N elements with direct indexing. Time complexity: O(k) where k is the window size.
Sourcepub fn get(&self, index: usize) -> Option<T>
pub fn get(&self, index: usize) -> Option<T>
Get a single element by index (0 = oldest, len-1 = newest)
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Get an iterator over the buffer elements (oldest to newest)
Sourcepub fn sliding_window_into(&self, size: usize, dest: &mut [T]) -> usize
pub fn sliding_window_into(&self, size: usize, dest: &mut [T]) -> usize
Zero-allocation sliding window - writes into pre-allocated buffer
§Performance
This method avoids heap allocation by writing directly into the provided buffer. For streaming applications processing millions of ticks, this eliminates allocation overhead completely.
§Arguments
size- Number of elements to read (from the most recent)dest- Pre-allocated destination buffer (must have sufficient capacity)
§Returns
Number of elements written to destination
Sourcepub fn sliding_window_slices(&self, size: usize) -> (&[T], &[T])
pub fn sliding_window_slices(&self, size: usize) -> (&[T], &[T])
Get the N most recent elements as contiguous slices
Since VecDeque may store data in two non-contiguous slices, this returns both slices that comprise the last N elements. For many use cases, this avoids allocation entirely.
§Returns
Tuple of (first_slice, second_slice) - second may be empty
Sourcepub fn get_recent_samples(&self, count: usize, dest: &mut [T]) -> usize
pub fn get_recent_samples(&self, count: usize, dest: &mut [T]) -> usize
Get the most recent N samples for circular convolution
Optimized for MODWT streaming where we need the last filter_len samples for computing a single new coefficient.
§Returns
Number of samples copied (may be less than filter_len if buffer not full)
Trait Implementations§
Source§impl<T: Clone> Clone for LocalRingBuffer<T>
impl<T: Clone> Clone for LocalRingBuffer<T>
Source§fn clone(&self) -> LocalRingBuffer<T>
fn clone(&self) -> LocalRingBuffer<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for LocalRingBuffer<T>
impl<T> RefUnwindSafe for LocalRingBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for LocalRingBuffer<T>where
T: Send,
impl<T> Sync for LocalRingBuffer<T>where
T: Sync,
impl<T> Unpin for LocalRingBuffer<T>where
T: Unpin,
impl<T> UnwindSafe for LocalRingBuffer<T>where
T: UnwindSafe,
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