[][src]Function natural_slice::permutation::encode_permutation

pub fn encode_permutation<T: Ord, Encoded: TryFrom<usize>>(
    data: &[T]
) -> Result<Encoded, Encoded::Error>

Encode a slice's permutation from the ordered state as a single number.

From a slice of up to 20 elements, produce a unique number that represents the order of the elements in that slice. This number can later be used to reconstitute the original slice permutation by calling decode_permutation.

This is the most space-efficient way of storing that information as every bit of entropy in the slice's permutation is represented by a bit in the permutation number. The maximum possible output is n!, where n is the size of the slice. 5! fits in a u8 8! fits in a u16 12! fits in a u32 20! fits in a u64