perm_to_lehm_idx
Notedocblock
perm_to_lehm_idx(P::Vector{<:Integer}) -> IntConvert a permutation P of 1:n into its 1-based lexicographic index, computed with the Lehmer code. The n! permutations are numbered 1, …, n! in lexicographic order. The ordinal patterns in this package are indexed this way.
This version allocates a work vector on every call. Inside loops, use perm_to_lehm_idx!, which reuses a preallocated one.
Arguments
P: a permutation of1:n, for example the result ofsortperm.
Returns
- The index of
P, an integer in1:factorial(n).
Examples
StatsOrdinalPatterns.perm_to_lehm_idx([1, 2, 3]) # 1
StatsOrdinalPatterns.perm_to_lehm_idx([1, 3, 2]) # 2
StatsOrdinalPatterns.perm_to_lehm_idx([3, 2, 1]) # 6