pub struct FixedWindowBuffer { /* private fields */ }Expand description
A bounded ring buffer storing the most recent capacity observations.
When the buffer is full, pushing a new value overwrites the oldest entry. Useful for fixed-window training or replay where only recent data matters.
Space complexity: O(capacity).
§Examples
use rill_ml::drift::FixedWindowBuffer;
let mut buf = FixedWindowBuffer::new(3).unwrap();
buf.push(1.0).unwrap();
buf.push(2.0).unwrap();
buf.push(3.0).unwrap();
assert_eq!(buf.mean(), Some(2.0));
// Overwrites the oldest entry (1.0).
buf.push(4.0).unwrap();
assert_eq!(buf.mean(), Some(3.0)); // (2 + 3 + 4) / 3Implementations§
Source§impl FixedWindowBuffer
impl FixedWindowBuffer
Sourcepub fn new(capacity: usize) -> Result<Self, RillError>
pub fn new(capacity: usize) -> Result<Self, RillError>
Create a new buffer with the given capacity.
capacity must be greater than zero.
Sourcepub fn push(&mut self, value: f64) -> Result<(), RillError>
pub fn push(&mut self, value: f64) -> Result<(), RillError>
Push a new value, overwriting the oldest entry if full.
value must be finite.
Trait Implementations§
Source§impl Clone for FixedWindowBuffer
impl Clone for FixedWindowBuffer
Source§fn clone(&self) -> FixedWindowBuffer
fn clone(&self) -> FixedWindowBuffer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FixedWindowBuffer
impl RefUnwindSafe for FixedWindowBuffer
impl Send for FixedWindowBuffer
impl Sync for FixedWindowBuffer
impl Unpin for FixedWindowBuffer
impl UnsafeUnpin for FixedWindowBuffer
impl UnwindSafe for FixedWindowBuffer
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