pub struct Series<T> { /* private fields */ }Expand description
A bounded, time-ordered ring buffer of samples.
Appending is O(1), the oldest samples drop off once capacity is reached, and range
lookups are binary searches. A push with the same time as the newest sample replaces it,
which is how a live candle or price updates in place.
Implementations§
Source§impl<T: Sample> Series<T>
impl<T: Sample> Series<T>
Sourcepub fn with_capacity(capacity: usize) -> Series<T>
pub fn with_capacity(capacity: usize) -> Series<T>
An empty series holding at most capacity samples (at least one).
Sourcepub fn set_capacity(&mut self, capacity: usize)
pub fn set_capacity(&mut self, capacity: usize)
Changes the capacity, dropping the oldest samples if needed.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Bumped on every change; compare it to skip work when nothing changed.
Sourcepub fn push(&mut self, sample: T) -> Result<Change, OutOfOrder>
pub fn push(&mut self, sample: T) -> Result<Change, OutOfOrder>
Appends sample, or replaces the newest one if it has the same time.
Sourcepub fn extend<I: IntoIterator<Item = T>>(
&mut self,
samples: I,
) -> Result<(), OutOfOrder>
pub fn extend<I: IntoIterator<Item = T>>( &mut self, samples: I, ) -> Result<(), OutOfOrder>
Pushes every sample in order, stopping at the first out-of-order one.
Sourcepub fn replace_all(&mut self, samples: Vec<T>)
pub fn replace_all(&mut self, samples: Vec<T>)
Replaces the contents with samples, which are sorted by time first (history loads).
Later duplicates of a time win.
Sourcepub fn update_last(&mut self, f: impl FnOnce(&mut T)) -> bool
pub fn update_last(&mut self, f: impl FnOnce(&mut T)) -> bool
Edits the newest sample in place (its time must not change).
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
Every sample, oldest first.
Sourcepub fn index_range(&self, start: Timestamp, end: Timestamp) -> Range<usize> ⓘ
pub fn index_range(&self, start: Timestamp, end: Timestamp) -> Range<usize> ⓘ
The index range of samples with start <= time <= end.
Sourcepub fn range(
&self,
start: Timestamp,
end: Timestamp,
) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
pub fn range( &self, start: Timestamp, end: Timestamp, ) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
Samples with start <= time <= end, oldest first.
Sourcepub fn range_padded(
&self,
start: Timestamp,
end: Timestamp,
) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
pub fn range_padded( &self, start: Timestamp, end: Timestamp, ) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
Like range plus one sample on each side when there is one, so lines
run to the edges of a viewport.
Trait Implementations§
Auto Trait Implementations§
impl<T> Forget for Series<T>
impl<T> Freeze for Series<T>
impl<T> Move for Series<T>
impl<T> RefUnwindSafe for Series<T>where
VecDeque<T>: RefUnwindSafe,
impl<T> Send for Series<T>
impl<T> Sync for Series<T>
impl<T> Unpin for Series<T>
impl<T> UnsafeUnpin for Series<T>where
VecDeque<T>: UnsafeUnpin,
impl<T> UnwindSafe for Series<T>where
VecDeque<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more