hopr_lib

Trait SMA

Source
pub trait SMA<T> {
    // Required methods
    fn push(&mut self, sample: T);
    fn average(&self) -> Option<T>;
    fn window_size(&self) -> usize;
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;

    // Provided method
    fn is_window_full(&self) -> bool { ... }
}
Expand description

Simple Moving Average trait.

The second-most useful filter type, bested only by coffee filters.

Required Methods§

Source

fn push(&mut self, sample: T)

Pushes a sample.

Source

fn average(&self) -> Option<T>

Calculates the moving average value. Returns None if no samples were added.

Source

fn window_size(&self) -> usize

Returns the window size.

Source

fn len(&self) -> usize

Returns the number of elements in the window. This value is always between 0 and window_size().

Source

fn is_empty(&self) -> bool

Indicates whether there are no samples.

Provided Methods§

Source

fn is_window_full(&self) -> bool

Indicates whether the window is fully occupied with samples.

Implementors§

Source§

impl<T, D> SMA<T> for NoSumSMA<T, D>
where T: for<'a> Sum<&'a T> + Div<D, Output = T>, D: From<u32>,

Source§

impl<T, D> SMA<T> for SingleSumSMA<T, D>
where T: AddAssign + SubAssign + Div<D, Output = T> + Copy, D: From<u32>,