Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

Buffer with maximum capacity that rotates itself.

Implementations§

Source§

impl Buffer

Source

pub fn from_array(capacity: usize, data: &[Num]) -> Result<Self, TAError>

Creates a new buffer from the data provided. If the data’s length is less than the capacity provided, the oldest values will be padded with the default value of T and and is_ready() will be false. If the data’s length is >= capacity, it takes the last values of data and is_ready() will be true.

§Arguments
  • capacity - Total size of the buffer, must be > 0.
  • data - Array of data to fill with. Newest -> Oldest.
Source

pub fn capacity(&self) -> usize

Maximum capacity the buffer can hold.

Source

pub fn is_ready(&self) -> bool

Checks if the buffer is ready indicating it has data to meet its capacity.

Source

pub fn oldest(&self) -> Num

Gets the oldest value in the buffer, this is the next value that will be removed.

Source

pub fn newest(&self) -> Num

Gets the newest value in the buffer, this value will current live the longest in the buffer.

Source

pub fn queue(&self) -> &[Num]

Returns the data held by the buffer from Oldest -> Newest. Index 0 being the oldest and next value to be removed. Index (len-1) being the newest data.

Source

pub fn shift(&mut self, value: Num) -> Num

Adds a new (newest) value to the buffer. Oldest value is removed and returned.

§Arguments
  • value - New (newest) value to add to the buffer.
Source

pub fn sum(&self) -> Num

Obtain the sum of the buffer.

Source

pub fn mean(&self) -> Num

Calculates the mean of the buffer.

Source

pub fn variance(&self, is_sample: bool) -> Num

Calculates the variance of the buffer.

§Arguments
  • is_sample - If the data is a Sample or Population, default should be True.
Source

pub fn stdev(&self, is_sample: bool) -> Num

Calculates the standard deviation of the buffer.

§Arguments
  • is_sample - If the data is a Sample or Population, default should be True.

Trait Implementations§

Source§

impl Debug for Buffer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl UnwindSafe for Buffer

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.