pub struct RunningAverage<V: Default, I: TimeInstant + Copy> { /* private fields */ }
Expand description
Represents running average calculation window. It is using specified window width that will consist of given number of accumulator buckets to ensure constant memory usage.
Implementations§
Source§impl<V: Default, I: TimeInstant + Copy> RunningAverage<V, I>
impl<V: Default, I: TimeInstant + Copy> RunningAverage<V, I>
Sourcepub fn new(duration: Duration) -> RunningAverage<V, I>
pub fn new(duration: Duration) -> RunningAverage<V, I>
Crate new RunningAverage instance that will average over window of width of given duration using 16 buckets.
Sourcepub fn with_capacity(
duration: Duration,
capacity: usize,
) -> RunningAverage<V, I>
pub fn with_capacity( duration: Duration, capacity: usize, ) -> RunningAverage<V, I>
Crate new RunningAverage instance that will average over window of width of given duration with specific number of buckets to use.
Sourcepub fn insert(&mut self, now: I, val: V)where
V: AddAssign<V>,
pub fn insert(&mut self, now: I, val: V)where
V: AddAssign<V>,
Insert value to be average over at given time instant. Panics if now is less than previous now - time cannot go backwards
Sourcepub fn measurement<'i>(&'i mut self, now: I) -> Measurement<V>
pub fn measurement<'i>(&'i mut self, now: I) -> Measurement<V>
Calculate running average using time window ending at given time instant. Panics if now is less than previous now - time cannot go backwards.
Trait Implementations§
Source§impl<V: Debug + Default, I: Debug + TimeInstant + Copy> Debug for RunningAverage<V, I>
impl<V: Debug + Default, I: Debug + TimeInstant + Copy> Debug for RunningAverage<V, I>
Source§impl<V: Default, I: TimeInstant + Copy> Default for RunningAverage<V, I>
impl<V: Default, I: TimeInstant + Copy> Default for RunningAverage<V, I>
Source§fn default() -> RunningAverage<V, I>
fn default() -> RunningAverage<V, I>
Crate new RunningAverage instance with window of 8 seconds width and 16 buckets.