Struct RunningAverage

Source
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>

Source

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.

Source

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.

Source

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

Source

pub fn measurement<'i>(&'i mut self, now: I) -> Measurement<V>
where V: Sum<&'i 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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Default, I: TimeInstant + Copy> Default for RunningAverage<V, I>

Source§

fn default() -> RunningAverage<V, I>

Crate new RunningAverage instance with window of 8 seconds width and 16 buckets.

Auto Trait Implementations§

§

impl<V, I> Freeze for RunningAverage<V, I>
where I: Freeze,

§

impl<V, I> RefUnwindSafe for RunningAverage<V, I>

§

impl<V, I> Send for RunningAverage<V, I>
where I: Send, V: Send,

§

impl<V, I> Sync for RunningAverage<V, I>
where I: Sync, V: Sync,

§

impl<V, I> Unpin for RunningAverage<V, I>
where I: Unpin, V: Unpin,

§

impl<V, I> UnwindSafe for RunningAverage<V, I>
where I: UnwindSafe, V: UnwindSafe,

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.