Function order_stat::median_of_medians [] [src]

pub fn median_of_medians<T: Ord>(array: &mut [T]) -> (usize, &mut T)

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.

Panics

This panics if array is empty.

Examples

// the numbers 0, 1, ..., 100.
let mut x = (0..101).rev().collect::<Vec<_>>();
let (_, &mut median) = order_stat::median_of_medians(&mut x);
assert!(30 <= median);
assert!(median <= 70);