smooth_buffer

Struct SmoothBuffer

Source
pub struct SmoothBuffer<const CAP: usize, T: Num> { /* private fields */ }
Expand description

Simple fixed size ringbuffer with fast averaging.

Implementations§

Source§

impl<const CAP: usize, T: Num> SmoothBuffer<CAP, T>

Source

pub fn new() -> Self

Creates a new, empty buffer.

Source

pub fn pre_filled(value: T) -> Self

Creates a new buffer pre-populated with a value, filled to capacity.

Source

pub fn average(&self) -> T

Fast! Sum is always kept up to date on push. No need to iterate.

Source

pub fn clear(&mut self)

Resets buffer to its default empty state.

Source

pub fn is_empty(&self) -> bool

True is buffer is empty.

Source

pub fn max(&self) -> T

The largest value so far, if any.

Source

pub fn min(&self) -> T

The smallest value so far, if any.

Source

pub fn capacity(&self) -> usize

The maximum number of items. Older items are discarded in favor of newer ones if capacity is exceeded.

Source

pub fn len(&self) -> usize

Current value count, will always be lower or equal to capacity.

Source

pub fn push(&mut self, value: T)

Push a single value.

Source

pub fn push_slice(&mut self, slice: &[T])

Pushes multiple values at once.

Source

pub fn iter(&self) -> Iter<'_, T>

Iterates through all values. Order of retrieval will likely NOT match order of input.

Source§

impl<const CAP: usize, T: Float> SmoothBuffer<CAP, T>

Source

pub fn gaussian_filter(&self) -> T

Gaussian smoothing. Much slower than a simple average, will actually iterate through all values and return a weighted sum.

Trait Implementations§

Source§

impl<const CAP: usize, T: Num> Default for SmoothBuffer<CAP, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const CAP: usize, T> Freeze for SmoothBuffer<CAP, T>
where T: Freeze,

§

impl<const CAP: usize, T> RefUnwindSafe for SmoothBuffer<CAP, T>
where T: RefUnwindSafe,

§

impl<const CAP: usize, T> Send for SmoothBuffer<CAP, T>
where T: Send,

§

impl<const CAP: usize, T> Sync for SmoothBuffer<CAP, T>
where T: Sync,

§

impl<const CAP: usize, T> Unpin for SmoothBuffer<CAP, T>
where T: Unpin,

§

impl<const CAP: usize, T> UnwindSafe for SmoothBuffer<CAP, T>
where T: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.