pub struct Mode { /* private fields */ }Expand description
Mode computation struct
This struct stores data to allow efficient computation of the mode. This struct takes linear space. It implements FromIterator to allow collection.
Examples
let nums = [2.0, 4.0, 8.0];
let mut mode = inc_stats::Mode::new();
for num in nums.iter() {
mode.add(num.clone());
}
assert_eq!(3, mode.count());let nums = [2.0, 4.0, 8.0];
let mode: inc_stats::Mode = nums.iter().cloned().collect();
assert_eq!(3, mode.count());Implementations
sourceimpl Mode
impl Mode
sourcepub fn modes(&self) -> Cloned<Iter<'_, f64>>
pub fn modes(&self) -> Cloned<Iter<'_, f64>>
Return an iterator of all of the modes
This iterator has read only reference to the mode data structure that must be dropped to continue modifying the mode. Constant time.
Examples
let mut mode = inc_stats::Mode::new();
{
let mut it = mode.modes();
assert!(it.next().is_none());
}
mode.add(5.0);
{
let mut it = mode.modes();
assert_eq!(Some(5.0), it.next());
assert!(it.next().is_none());
}
mode.add(3.0);
{
let mut it = mode.modes();
assert_eq!(Some(5.0), it.next());
assert_eq!(Some(3.0), it.next());
assert!(it.next().is_none());
}
mode.add(3.0);
{
let mut it = mode.modes();
assert_eq!(Some(3.0), it.next());
assert!(it.next().is_none());
}sourcepub fn mode(&self) -> Option<f64>
pub fn mode(&self) -> Option<f64>
Return the current mode
If multiple modes exist, this returns the first element that reached the largest count. NaNs are ignored when computing the mode. Constant time.
Examples
let nums = [2.0, 4.0, std::f64::NAN, 4.0];
let mode: inc_stats::Mode = nums.iter().cloned().collect();
assert!((4.0 - mode.mode().unwrap()).abs() < 1.0e-6);let mode = inc_stats::Mode::new();
assert!(mode.mode().is_none());sourcepub fn mode_count(&self) -> i64
pub fn mode_count(&self) -> i64
Return the number of times the mode occurred
Constant time.
Examples
let nums = [2.0, 4.0, std::f64::NAN, 4.0];
let mode: inc_stats::Mode = nums.iter().cloned().collect();
assert_eq!(2, mode.mode_count());Trait Implementations
sourceimpl FromIterator<f64> for Mode
impl FromIterator<f64> for Mode
sourcefn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = f64>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = f64>,
Creates a value from an iterator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Mode
impl Send for Mode
impl Sync for Mode
impl Unpin for Mode
impl UnwindSafe for Mode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more