Maintainer | Anders Claesson <anders.claesson@gmail.com> |
---|---|

Safe Haskell | None |

Generating permutations: rank and unrank

# Documentation

module Data.CLongArray

type Perm = CLongArraySource

A permutation is just a `CLongArray`

. By convention a permutation
of size `n`

is understood to be a permutation of `[0..n-1]`

.

mkPerm :: Ord a => [a] -> PermSource

Construct a permutation from a list of elements. As opposed to
`fromList`

this is a safe function in the sense that the output of
`mkPerm xs`

is guaranteed to be a permutation of `[0..length xs-1]`

.
E.g., `mkPerm "baxa" == fromList [2,0,3,1]`

.

The rank of the given permutation, where the rank is defined as in [W. Myrvold and F. Ruskey, Ranking and Unranking Permutations in Linear Time, Information Processing Letters, 79 (2001) 281-284].