pub struct MinMax<T> { /* private fields */ }
Expand description
A commutative data structure for tracking minimum and maximum values and detecting sort order in a stream of data.
Implementations§
Source§impl<T: PartialOrd + Clone> MinMax<T>
impl<T: PartialOrd + Clone> MinMax<T>
Sourcepub fn add(&mut self, sample: T)
pub fn add(&mut self, sample: T)
Add a sample to the data and track min/max, the sort order & “sortiness”.
Sourcepub const fn min(&self) -> Option<&T>
pub const fn min(&self) -> Option<&T>
Returns the minimum of the data set.
None
is returned if and only if the number of samples is 0
.
Sourcepub const fn max(&self) -> Option<&T>
pub const fn max(&self) -> Option<&T>
Returns the maximum of the data set.
None
is returned if and only if the number of samples is 0
.
Sourcepub fn sort_order(&self) -> SortOrder
pub fn sort_order(&self) -> SortOrder
Returns the current sort order of the data.
Sourcepub fn sortiness(&self) -> f64
pub fn sortiness(&self) -> f64
Calculates a “sortiness” score for the data, indicating how close it is to being sorted.
Returns a value between -1.0 and 1.0:
- 1.0 indicates perfectly ascending order
- -1.0 indicates perfectly descending order
- Values in between indicate the general tendency towards ascending or descending order
- 0.0 indicates either no clear ordering or empty/single-element collections
§Examples
use stats::MinMax;
let mut asc: MinMax<i32> = vec![1, 2, 3, 4, 5].into_iter().collect();
assert_eq!(asc.sortiness(), 1.0);
let mut desc: MinMax<i32> = vec![5, 4, 3, 2, 1].into_iter().collect();
assert_eq!(desc.sortiness(), -1.0);
let mut mostly_asc: MinMax<i32> = vec![1, 2, 4, 3, 5].into_iter().collect();
assert!(mostly_asc.sortiness() > 0.0); // Positive but less than 1.0
Trait Implementations§
Source§impl<T: PartialOrd> Default for MinMax<T>
impl<T: PartialOrd> Default for MinMax<T>
Source§impl<'de, T> Deserialize<'de> for MinMax<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for MinMax<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: PartialOrd + Clone> Extend<T> for MinMax<T>
impl<T: PartialOrd + Clone> Extend<T> for MinMax<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, it: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, it: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T: PartialOrd + Clone> FromIterator<T> for MinMax<T>
impl<T: PartialOrd + Clone> FromIterator<T> for MinMax<T>
impl<T: Copy> Copy for MinMax<T>
impl<T: Eq> Eq for MinMax<T>
impl<T> StructuralPartialEq for MinMax<T>
Auto Trait Implementations§
impl<T> Freeze for MinMax<T>where
T: Freeze,
impl<T> RefUnwindSafe for MinMax<T>where
T: RefUnwindSafe,
impl<T> Send for MinMax<T>where
T: Send,
impl<T> Sync for MinMax<T>where
T: Sync,
impl<T> Unpin for MinMax<T>where
T: Unpin,
impl<T> UnwindSafe for MinMax<T>where
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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