Function out::max_by

source ·
pub fn max_by<T>(
    v: &mut [T],
    n: usize,
    cmp: impl FnMut(&T, &T) -> Ordering
) -> &mut [T]
Expand description

Get the n largest items with a comparator function.

This method is stable, i.e. it preserves the order of equal elements.

Examples

let mut v = [-5, 4, 1, -3, 2];
let min = out::max_by(&mut v, 3, |a, b| b.cmp(a));
assert_eq!(min, [1, -3, -5]);