pub struct ElasticRingBuffer<T: Clone> { /* private fields */ }
Expand description
A FIFO buffer with a fixed length that adjusts to requests that would otherwise overflow or underflow.
When an ElasticRingBuffer
doesn’t have enough elements to
satisfy a request, it will “stretch” the values it does have by
repeating them to fill the request.
And when the buffer is getting too full (past its ideal max length), elements will be uniformly dropped to return the queue to its ideal length.
Implementations§
Source§impl<T: Clone> ElasticRingBuffer<T>
impl<T: Clone> ElasticRingBuffer<T>
Sourcepub fn new(size: usize, value: T, ideal_max_len: usize) -> ElasticRingBuffer<T>
pub fn new(size: usize, value: T, ideal_max_len: usize) -> ElasticRingBuffer<T>
Create a new ElasticRingBuffer
with the given size. value
will be used as the default value for the
queue. ideal_max_len
is the threshold where the buffer will
begin dropping elements during requests
Sourcepub fn pop_front_slice(&mut self, values: &mut [T]) -> ElasticPopResult
pub fn pop_front_slice(&mut self, values: &mut [T]) -> ElasticPopResult
Fill values
with elements. See ElasticPopResult
for the
possible outcomes of this request.
Sourcepub fn push_back_slice(&mut self, values: &[T]) -> bool
pub fn push_back_slice(&mut self, values: &[T]) -> bool
Add all values
to the buffer. If there is not enough room in
the queue then no values are added and the return value is
false