Trait SMA
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;
fn clear(&mut self);
// 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§
fn push(&mut self, sample: T)
fn push(&mut self, sample: T)
Pushes a sample.
fn average(&self) -> Option<T>
fn average(&self) -> Option<T>
Calculates the moving average value.
Returns None
if no samples were added.
fn window_size(&self) -> usize
fn window_size(&self) -> usize
Returns the window size.
fn len(&self) -> usize
fn len(&self) -> usize
Returns the number of elements in the window.
This value is always between 0 and window_size()
.
fn clear(&mut self)
fn clear(&mut self)
Clears all the samples.
Provided Methods§
fn is_window_full(&self) -> bool
fn is_window_full(&self) -> bool
Indicates whether the window is fully occupied with samples.