Function rudac::algo::find::max_with [−][src]
pub fn max_with<T, F>(slice: &mut [T], compare: &F) -> usize where
F: Fn(&T, &T) -> Ordering,
Expand description
Returns index of largest item in the slice using a customized closure for comparison
It is equivalent to calling kth_with(slice, slice.len()-1)
Arguments
slice
: slice of unordered datacompare
: custom comparing closure
Examples
use rudac::algo::find::max_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 largest point based on their y axis only
let largest_item_index = max_with(&mut vec, &|x1,x2| {x1.1.cmp(&x2.1)});
assert_eq!(vec[largest_item_index], (1,10));