Struct simple_moving_average::SumTreeSMA [−][src]
pub struct SumTreeSMA<Sample, Divisor, const WINDOW_SIZE: usize> { /* fields omitted */ }Expand description
An SMA implementation that caches the sum of all samples currently in the sample window as a tree of sums.
Implementations
impl<Sample: Copy + Zero, Divisor, const WINDOW_SIZE: usize> SumTreeSMA<Sample, Divisor, WINDOW_SIZE>
impl<Sample: Copy + Zero, Divisor, const WINDOW_SIZE: usize> SumTreeSMA<Sample, Divisor, WINDOW_SIZE>
Constructs a new SumTreeSMA with window size WINDOW_SIZE. This constructor is
only available for Sample types that implement num_traits::Zero. If the Sample type
does not, use the from_zero constructor instead.
Note that the Divisor type usually cannot be derived by the compiler when using this
constructor and must be explicitly stated, even if it is the same as the Sample type.
Constructs a new SumTreeSMA with window size WINDOW_SIZE from the given
zero sample. If the Sample type implements num_traits::Zero, the
new constructor might be preferable to this.
Trait Implementations
impl<Sample, Divisor, const WINDOW_SIZE: usize> SMA<Sample, Divisor, WINDOW_SIZE> for SumTreeSMA<Sample, Divisor, WINDOW_SIZE> where
Sample: Copy + Add<Output = Sample> + Div<Divisor, Output = Sample>,
Divisor: FromPrimitive,
impl<Sample, Divisor, const WINDOW_SIZE: usize> SMA<Sample, Divisor, WINDOW_SIZE> for SumTreeSMA<Sample, Divisor, WINDOW_SIZE> where
Sample: Copy + Add<Output = Sample> + Div<Divisor, Output = Sample>,
Divisor: FromPrimitive,
Adds a sample to the series of samples. If the sample window is full, this will cause the oldest sample to be dropped, i.e. no longer contribute to the average. Read more
Returns the simple moving average value of all the samples in the sample window.
Returns the most recently added sample, if any.
Returns the total number of samples currently in the in the sample window. This value never exceeds the sample window size. Read more
Returns the maximum number of samples that fit in the sample window.