Function permutation::permutation::sort_unstable_by_key
source · [−]pub fn sort_unstable_by_key<T, S, B, F>(slice: S, f: F) -> Permutation where
B: Ord,
S: AsRef<[T]>,
F: FnMut(&T) -> B,
Expand description
Return the permutation that would sort a given slice by a key function, but might not preserve the order of equal elements.
This is the same as permutation::sort_unstable()
except that it allows you to specify
the key function simliar to std::slice.sort_unstable_by_key()
Examples
let mut vec = vec![2, 4, 6, 8, 10, 11];
let permutation = permutation::sort_unstable_by_key(&vec, |a| a % 3);
let permuted = permutation.apply_slice(&vec);
vec.sort_by_key(|a| a % 3);
assert_eq!(vec, permuted);