Skip to main content

MinWindow

Struct MinWindow 

Source
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

Source

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.

Source

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.

Source

pub fn min(&self) -> Option<i64>

Current minimum, None when empty.

Source

pub fn len(&self) -> usize

Entries currently held.

Source

pub fn is_empty(&self) -> bool

True when no sample is held.

Source

pub fn overflows(&self) -> u32

Entries dropped because the cap was hit.

Source

pub fn clear(&mut self)

Drop every sample (the overflow counter is kept).

Trait Implementations§

Source§

impl Clone for MinWindow

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MinWindow

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.