@maruaudio/dsp/math/permutation-six encodes an ordering of six stable identities (0 to 5) as its lexicographic rank, 0 to 719, and decodes a rank back into an order. It is the Lehmer code with fixed factorial weights 120, 24, 6, 2, 1, 1 and a six-bit "used" mask, so both directions run in bounded loops over caller-owned Int32Array storage. The identity order 0, 1, 2, 3, 4, 5 is rank 0.
Functions
| Name | Inputs | Output | Domain as coded |
|---|---|---|---|
rankPermutationSix | order: Int32Array | rank 0..719, or −1 | −1 unless the array has length 6 and holds each of 0..5 exactly once |
tryUnrankPermutationSix | rank, output: Int32Array | true and fills output[0..5], or false | false for NaN, ±Infinity, fractions, ranks outside 0..719, or an output shorter than 6; ranks never wrap |
PERMUTATION_SIX_SIZE, PERMUTATION_SIX_COUNT | constants | 6, 720 |
Lifecycle
None. Stateless validation and codec operations; the caller owns the arrays.
When to use it
Store the order of a six-slot serial effect chain as one integer parameter, so a Processor and its face agree on the same order. The Multifx Processor stack and face share it.
Limits
- Exactly six items; there is no generic size.
- On a rejected rank,
outputis left as it was; a valid unrank writes all six slots. An output longer than six keeps its extra slots.