pub struct DelayBuffer { /* private fields */ }Available on crate feature
alloc only.Expand description
Circular buffer storing the last capacity observation vectors.
Observations are pushed one at a time. Once capacity observations have
been stored, the buffer is “ready” and older observations are overwritten
in FIFO order.
§Examples
use irithyll_core::reservoir::DelayBuffer;
let mut buf = DelayBuffer::new(3);
buf.push(&[1.0]);
buf.push(&[2.0]);
buf.push(&[3.0]);
assert!(buf.is_ready());
assert_eq!(buf.get(0).unwrap(), &[3.0]); // most recent
assert_eq!(buf.get(1).unwrap(), &[2.0]);
assert_eq!(buf.get(2).unwrap(), &[1.0]); // oldestImplementations§
Source§impl DelayBuffer
impl DelayBuffer
Sourcepub fn push(&mut self, obs: &[f64])
pub fn push(&mut self, obs: &[f64])
Push a new observation into the buffer.
If the buffer is full, the oldest observation is overwritten.
Sourcepub fn get(&self, delay_idx: usize) -> Option<&[f64]>
pub fn get(&self, delay_idx: usize) -> Option<&[f64]>
Get the observation at the given delay index.
delay_idx = 0returns the most recently pushed observation.delay_idx = 1returns the previous observation.- Returns
Noneifdelay_idx >= len().
Auto Trait Implementations§
impl Freeze for DelayBuffer
impl RefUnwindSafe for DelayBuffer
impl Send for DelayBuffer
impl Sync for DelayBuffer
impl Unpin for DelayBuffer
impl UnsafeUnpin for DelayBuffer
impl UnwindSafe for DelayBuffer
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
Mutably borrows from an owned value. Read more