perm_to_lehm_idx!
Notedocblock
perm_to_lehm_idx!(P::Vector{<:Integer}, used::Vector{<:Integer}) -> IntVersion of perm_to_lehm_idx without allocations: convert a permutation P of 1:n into its 1-based lexicographic index, using the preallocated work vector used.
used is modified: on return, every entry is 1. Reset it with fill!(used, 0) before the next call. P is not modified.
Arguments
P: a permutation of1:n, for example the result ofsortperm.used: work vector of lengthnwhose entries are all zero on input.
Returns
- The index of
P, an integer in1:factorial(n).
Examples
used = zeros(Int, 3)
StatsOrdinalPatterns.perm_to_lehm_idx!([3, 1, 2], used) # 5
fill!(used, 0) # required before the next call