pub struct CircularBuffer<O, A> { /* private fields */ }Expand description
A fixed-capacity circular replay buffer.
Stores experience tuples and overwrites the oldest when full.
Implements rl_traits::ReplayBuffer so it’s usable by any algorithm
that depends on that trait, not just DQN.
§Implementation notes
Uses a Vec pre-allocated to capacity with a write cursor that wraps
around. This avoids any allocation after construction and gives O(1) push
and O(batch_size) sample.
Implementations§
Trait Implementations§
Source§impl<O, A> ReplayBuffer<O, A> for CircularBuffer<O, A>
impl<O, A> ReplayBuffer<O, A> for CircularBuffer<O, A>
Source§fn push(&mut self, experience: Experience<O, A>)
fn push(&mut self, experience: Experience<O, A>)
Add a new experience to the buffer. Read more
Source§fn sample(&self, batch_size: usize, rng: &mut impl Rng) -> Vec<Experience<O, A>>
fn sample(&self, batch_size: usize, rng: &mut impl Rng) -> Vec<Experience<O, A>>
Sample a random batch of
batch_size experiences. Read moreAuto Trait Implementations§
impl<O, A> Freeze for CircularBuffer<O, A>
impl<O, A> RefUnwindSafe for CircularBuffer<O, A>where
O: RefUnwindSafe,
A: RefUnwindSafe,
impl<O, A> Send for CircularBuffer<O, A>
impl<O, A> Sync for CircularBuffer<O, A>
impl<O, A> Unpin for CircularBuffer<O, A>
impl<O, A> UnsafeUnpin for CircularBuffer<O, A>
impl<O, A> UnwindSafe for CircularBuffer<O, A>where
O: UnwindSafe,
A: 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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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