
#include "aux0/swap.h"
#include "fxttypes.h"


void
ffact2cyclic(const ulong *fc, ulong n, ulong *x)
// Generate cyclic permutation (standard representation) in x[]
//   from the (n-2) digit factorial number in fc[0,...,n-3].
// Falling radices:  [n-1, ..., 3, 2]
{
    for (ulong k=0; k<n; ++k)  x[k] = k;

    for (ulong k=n-1; k>1; --k)
    {
        ulong z = n-1-k; // 0, ..., n-3
        ulong i = fc[z];
        swap2(x[k], x[i]);
    }

    if ( n>1 )  swap2(x[0], x[1]);
}
// -------------------------


void
rfact2cyclic(const ulong *fc, ulong n, ulong *x)
// Generate cyclic permutation (standard representation) in x[]
//   from the (n-2) digit factorial number in fc[0,...,n-3].
// Rising radices:  [2, 3, ..., n-1]
{
    for (ulong k=0; k<n; ++k)  x[k] = k;

    for (ulong k=n-1; k>1; --k)
    {
        ulong i = fc[k-2];  // k-2 == n-3, ..., 0
        swap2(x[k], x[i]);
    }

    if ( n>1 )  swap2(x[0], x[1]);
}
// -------------------------

