Struct inc_stats::Mode[][src]

pub struct Mode<T: Float + ToBytes = f64> { /* fields omitted */ }

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 mut mode = inc_stats::Mode::new();
for &num in &[2.0, 4.0, 8.0] {
    mode.add(num);
}
assert_eq!(3, mode.count());
let mode: inc_stats::Mode = [2.0, 4.0, 8.0].iter().collect();
assert_eq!(3, mode.count());

Implementations

impl<T: Float + ToBytes> Mode<T>[src]

pub fn new() -> Self[src]

Create a new Mode object with no data

pub fn add(&mut self, rval: impl DerefCopy<Output = T>)[src]

Add a data point

pub fn count(&self) -> usize[src]

Get the number of data points

pub fn modes(&self) -> Copied<Iter<'_, T>>[src]

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());
}

pub fn mode(&self) -> Option<T>[src]

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 mode: inc_stats::Mode = [2.0, 4.0, std::f64::NAN, 4.0].iter().collect();
assert_eq!(4.0, mode.mode().unwrap());
let mode = inc_stats::Mode::<f64>::new();
assert!(mode.mode().is_none());

pub fn mode_count(&self) -> usize[src]

Return the number of times the mode occurred

Constant time.

Examples

let mode: inc_stats::Mode = [2.0, 4.0, std::f64::NAN, 4.0].iter().collect();
assert_eq!(2, mode.mode_count());

Trait Implementations

impl<T: Debug + Float + ToBytes> Debug for Mode<T>[src]

impl<T: Float + ToBytes, V: DerefCopy<Output = T>> FromIterator<V> for Mode<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Mode<T> where
    T: RefUnwindSafe

impl<T> Send for Mode<T> where
    T: Send

impl<T> Sync for Mode<T> where
    T: Sync

impl<T> Unpin for Mode<T> where
    T: Unpin

impl<T> UnwindSafe for Mode<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.