pub struct RealTimeRunningAverage<V: Default, TS: TimeSource = RealTimeSource> { /* private fields */ }
Expand description
Represents running average calculation window where shift
and measurement
are using given time source to obtain value of now
instant.
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> RealTimeRunningAverage<V, RealTimeSource>
impl<V: Default> RealTimeRunningAverage<V, RealTimeSource>
Sourcepub fn new(duration: Duration) -> RealTimeRunningAverage<V, RealTimeSource>
pub fn new(duration: Duration) -> RealTimeRunningAverage<V, RealTimeSource>
Crate new instance with window of given width duration and using RealTimeSource as time source for now
instant.
Note: new() is parametrizing output to RealTimeSource as this cannot be inferred otherwise.
Source§impl<V: Default, TS: TimeSource> RealTimeRunningAverage<V, TS>
impl<V: Default, TS: TimeSource> RealTimeRunningAverage<V, TS>
Sourcepub fn with_time_source(
duration: Duration,
capacity: usize,
time_source: TS,
) -> RealTimeRunningAverage<V, TS>
pub fn with_time_source( duration: Duration, capacity: usize, time_source: TS, ) -> RealTimeRunningAverage<V, TS>
Crate new instance with window of given width duration and using given as time source for now
instant.
Sourcepub fn insert(&mut self, val: V)where
V: AddAssign<V>,
pub fn insert(&mut self, val: V)where
V: AddAssign<V>,
Insert value to be average over now. Panics if time source time goes backwards.
Sourcepub fn measurement<'i>(&'i mut self) -> Measurement<V>
pub fn measurement<'i>(&'i mut self) -> Measurement<V>
Calculate running average using time window ending now. Panics if time source time goes backwards.
Sourcepub fn time_source(&mut self) -> &mut TS
pub fn time_source(&mut self) -> &mut TS
Return mutable reference to time source used.