Function rudac::algo::find::median_with [−][src]
pub fn median_with<T, F>(slice: &mut [T], compare: &F) -> usize where
F: Fn(&T, &T) -> Ordering,
Expand description
Returns index of median item in the slice using a customized closure for comparison
It is equivalent to calling kth_with(slice, slice.len()/2)
Arguments
slice
: slice of unordered datacompare
: custom comparing closure
Examples
use rudac::algo::find::median_with;
// consider a vector of 2d points
let mut vec = vec![(1, 10), (2,6), (3,1), (3,4), (4,2), (5,3), (6,7), (8,9), (9,8), (10,5)];
// find index of median point based on their y axis only
let median_item_index = median_with(&mut vec, &|x1,x2| {x1.1.cmp(&x2.1)});
assert_eq!(vec[median_item_index], (2,6));