Function order_stat::median_of_medians
source · [−]Expand description
Calculate an approximate median of array
.
The return value is the index/reference to some value of array
that is guaranteed to lie between the 30th and 70th percentiles of
the values in array
. That is, it both is not smaller and not
larger than than at least 30% of the elements of array
.
This is equivalent to median_of_medians_by(array, Ord::cmp)
.
Panics
This panics if array
is empty.
Examples
// the numbers 0, 1, ..., 100.
let mut v = (0..101).rev().collect::<Vec<_>>();
let (_, &mut median) = order_stat::median_of_medians(&mut v);
assert!(30 <= median);
assert!(median <= 70);