pub struct NoSumSMA<T, D = T> { /* private fields */ }
Expand description
Basic implementation of Simple Moving Average (SMA).
The maximum window size is bound by 2^32 - 1.
Useful mainly for floating-point types, as it does not accumulate floating point error with each sample.
Requires O(N)
of memory and O(N)
for average computation, N
being window size.
The divisor argument D
is used only for such types T
that do not implement From<u32>
(such as Duration
,…).
Implementations§
Source§impl<T, D> NoSumSMA<T, D>
impl<T, D> NoSumSMA<T, D>
Sourcepub fn new(window_size: usize) -> Self
pub fn new(window_size: usize) -> Self
Creates an empty SMA instance with the given window size. The maximum window size is u32::MAX and must be greater than 1.
Sourcepub fn new_with_samples<I>(window_size: usize, initial_samples: I) -> Selfwhere
I: IntoIterator<Item = T>,
pub fn new_with_samples<I>(window_size: usize, initial_samples: I) -> Selfwhere
I: IntoIterator<Item = T>,
Creates SMA instance given window size and some initial samples.
Trait Implementations§
Source§impl<'de, T, D> Deserialize<'de> for NoSumSMA<T, D>where
T: Deserialize<'de>,
impl<'de, T, D> Deserialize<'de> for NoSumSMA<T, D>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T, D> SMA<T> for NoSumSMA<T, D>
impl<T, D> SMA<T> for NoSumSMA<T, D>
Source§fn average(&self) -> Option<T>
fn average(&self) -> Option<T>
Calculates the moving average value.
Returns
None
if no samples were added.Source§fn window_size(&self) -> usize
fn window_size(&self) -> usize
Returns the window size.
Source§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()
.Source§fn is_window_full(&self) -> bool
fn is_window_full(&self) -> bool
Indicates whether the window is fully occupied
with samples.
impl<T, D> StructuralPartialEq for NoSumSMA<T, D>
Auto Trait Implementations§
impl<T, D> Freeze for NoSumSMA<T, D>
impl<T, D> RefUnwindSafe for NoSumSMA<T, D>where
D: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, D> Send for NoSumSMA<T, D>
impl<T, D> Sync for NoSumSMA<T, D>
impl<T, D> Unpin for NoSumSMA<T, D>
impl<T, D> UnwindSafe for NoSumSMA<T, D>where
D: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more