decode

Function decode 

Source
pub fn decode<T: Clone + Ord>(xs: &[T], p: usize) -> Vec<T>
Expand description

Returns the multiset permutation of the value p to the slice xs.

The returned multiset 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 multiset permutation to the slice.

§Panics

Panics in debug mode if xs is not non-decreasing or p is out of range.

§Examples

assert_eq!(decode(&[0, 0, 1], 0), &[0, 0, 1]);
assert_eq!(decode(&[0, 0, 1], 1), &[0, 1, 0]);
assert_eq!(decode(&[0, 0, 1], 2), &[1, 0, 0]);