pub struct MinWindow { /* private fields */ }Expand description
Monotonic-deque sliding minimum of (time, value) samples.
Amortised O(1) per push. The deque is pre-sized to max_samples + 1 so no
allocation happens after construction; over the cap the oldest entry is
dropped (the window shrinks) and counted.
Implementations§
Source§impl MinWindow
impl MinWindow
Sourcepub fn new(window: Duration, max_samples: u16) -> Result<Self, Error>
pub fn new(window: Duration, max_samples: u16) -> Result<Self, Error>
New window of window holding at most max_samples entries.
§Errors
Error::ZeroLengthWindow when window is zero.
Sourcepub fn push(&mut self, t: u64, v: i64) -> i64
pub fn push(&mut self, t: u64, v: i64) -> i64
Add a sample at time t (non-decreasing) and return the minimum of
the samples within the trailing window (inclusive of this one).
Long-gap rule. If the silence since the previous sample is at least the window, expiry is skipped for this one push: otherwise a delivery stall longer than the window (2 s, 4 s) would evict the whole pre-stall baseline and the first post-stall sample would read a PDV of 0. The next push (normal spacing) expires the old entries as usual.