Function order_stat::kth_by
source · [−]pub fn kth_by<T, F>(array: &mut [T], k: usize, cmp: F) -> &mut T where
F: FnMut(&T, &T) -> Ordering,
Expand description
Compute the element that is the k
th order statistic in the
ordering defined by cmp
(that is, the k
th element of array.sort_by(cmp)
).
See special case kth
for more details. It is equivalent to
kth_by(array, k, Ord::cmp)
.
Panics
If k >= array.len()
, kth_by
panics.
Examples
let mut v = [10.0, 0.0, -10.0, 20.0];
// no NaNs, so partial_cmp works
let kth = order_stat::kth_by(&mut v, 2, |x, y| x.partial_cmp(y).unwrap());
assert_eq!(*kth, 10.0);