pub struct Buffer { /* private fields */ }Expand description
Buffer with maximum capacity that rotates itself.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn from_array(capacity: usize, data: &[Num]) -> Result<Self, TAError>
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.
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Checks if the buffer is ready indicating it has data to meet its capacity.
Sourcepub fn oldest(&self) -> Num
pub fn oldest(&self) -> Num
Gets the oldest value in the buffer, this is the next value that will be removed.
Sourcepub fn newest(&self) -> Num
pub fn newest(&self) -> Num
Gets the newest value in the buffer, this value will current live the longest in the buffer.
Sourcepub fn queue(&self) -> &[Num] ⓘ
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.
Sourcepub fn shift(&mut self, value: Num) -> Num
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.