[−][src]Function out::slice::min_unstable_by
pub fn min_unstable_by<T>(
v: &mut [T],
n: usize,
cmp: impl FnMut(&T, &T) -> Ordering
) -> &mut [T]
Returns the n
smallest items with a comparator function.
This sort is unstable (i.e. may reorder equal elements), in-place
(i.e. does not allocate), and typically faster than min_by
.
Panics
Panics if n > len
.
Examples
let mut v = [-5, 4, 1, -3, 2]; let max = out::slice::min_unstable_by(&mut v, 3, |a, b| b.cmp(a)); assert_eq!(max, [1, 2, 4]);