Function mayda::utility::select_m
[−]
[src]
pub fn select_m<T: Copy + Ord>(array: &mut [T], k: usize) -> T
A modified version of the Floyd-Rivest algorithm with fewer comparisions and fewer swaps, specialized for the case of slices with length < 500. The modifications may not be known in the literature. Intended to be used to find the median of a block.
Examples
use mayda::utility::select_m; let mut array: [u32; 7] = [1, 4, 2, 8, 5, 7, 1]; let min: u32 = select_m(&mut array, 0); let max: u32 = select_m(&mut array, 6); let med: u32 = select_m(&mut array, 3); assert_eq!(1, min); assert_eq!(8, max); assert_eq!(4, med);