Skip to main content

DelayBuffer

Struct DelayBuffer 

Source
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]); // oldest

Implementations§

Source§

impl DelayBuffer

Source

pub fn new(capacity: usize) -> Self

Create a new delay buffer with the given capacity.

§Panics

Panics if capacity is 0.

Source

pub fn push(&mut self, obs: &[f64])

Push a new observation into the buffer.

If the buffer is full, the oldest observation is overwritten.

Source

pub fn get(&self, delay_idx: usize) -> Option<&[f64]>

Get the observation at the given delay index.

  • delay_idx = 0 returns the most recently pushed observation.
  • delay_idx = 1 returns the previous observation.
  • Returns None if delay_idx >= len().
Source

pub fn is_ready(&self) -> bool

Whether the buffer has been filled to capacity at least once.

NG-RC requires is_ready() before building features, because all k delay slots must be populated.

Source

pub fn len(&self) -> usize

Number of observations currently stored (at most capacity).

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub fn capacity(&self) -> usize

The maximum number of observations this buffer can hold.

Source

pub fn reset(&mut self)

Reset the buffer, discarding all stored observations.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.