Struct inc_stats::Percentiles

source ·
pub struct Percentiles { /* private fields */ }
Expand description

Data percentile struct

This struct stores data to allow efficient computation of percentiles. This struct takes linear space. It implements FromIterator to allow collection.

Examples

let nums = [2.0, 4.0, 8.0];
let mut percs = inc_stats::Percentiles::new();
for num in nums.iter() {
    percs.add(num.clone());
}
assert_eq!(3, percs.count());
let nums = [2.0, 4.0, 8.0];
let percs: inc_stats::Percentiles = nums.iter().cloned().collect();
assert_eq!(3, percs.count());

Implementations

Create a new Percentiles object with no data

Add a data point

Get the number of data points

Get a number of percentiles

This takes linear time in the number of added data points, and log linear in the number of percentiles. This will be marginally more efficient than calling percentile repeatedly in a bad order.

Examples:
let nums = [1.0, 3.0, 7.0];
let mut percs: inc_stats::Percentiles = nums.iter().cloned().collect();
let quarts = percs.percentiles([0.75, 0.25, 0.5].iter().cloned()).unwrap();
assert!((5.0 - quarts[0]).abs() < 1.0e-6);
assert!((2.0 - quarts[1]).abs() < 1.0e-6);
assert!((3.0 - quarts[2]).abs() < 1.0e-6);

Get a percentile

Linear time.

Examples:
let nums = [1.0, 5.0];
let mut percs: inc_stats::Percentiles = nums.iter().cloned().collect();
let quart = percs.percentile(&0.25).unwrap();
assert!((2.0 - quart).abs() < 1.0e-6);

Get the median

Linear time.

Examples:
let nums = [1.0, 5.0, 100.0];
let mut percs: inc_stats::Percentiles = nums.iter().cloned().collect();
let med = percs.median().unwrap();
assert!((5.0 - med).abs() < 1.0e-6);

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.