pub fn decode<T: Clone + Ord>(xs: &[T], p: usize) -> Vec<T>
Expand description
Returns the permutation of the value p
to the slice xs
.
The returned permutation can be encoded with encode
to get back p
.
let xs = decode(&xs, p);
assert_eq!(encode(&xs), p);
See decode_mut
for a version that applies the permutation to the slice.
§Panics
Panics in debug mode if xs
is not increasing or p
is out of range.
§Examples
assert_eq!(decode(&[0, 1, 2], 0), &[0, 1, 2]);
assert_eq!(decode(&[0, 1, 2], 1), &[0, 2, 1]);
assert_eq!(decode(&[0, 1, 2], 2), &[1, 0, 2]);