[][src]Function out::max_unstable_by_key

pub fn max_unstable_by_key<T, K: Ord>(
    v: &mut [T],
    n: usize,
    cmp: impl FnMut(&T) -> K
) -> &mut [T]

Get the n largest items with a key extraction function.

This method is not stable, i.e. it may not preserve the order of equal elements. This method should be faster than max_unstable_by_key in most cases, and can be used with no_std.

Panics

Panics if n > len.

Examples

let mut v = [-5_i32, 4, 1, -3, 2];
let max = out::max_unstable_by_key(&mut v, 3, |a| a.abs());
assert_eq!(max, [-3, 4, -5]);