Copyright | Anders Claesson 2013-2016 |
---|---|
Maintainer | Anders Claesson <anders.claesson@gmail.com> |
Safe Haskell | None |
Language | Haskell98 |
Generating permutations: rank and unrank
Documentation
module Sym.Internal.CLongArray
type Perm = CLongArray Source #
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] -> Perm Source #
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]
.
rank :: Perm -> Integer Source #
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].