|7:      !"#$%&'()*+,-./0123456789 experimental%Patrick Perry <patperry@stanford.edu>:;<=>?@ABCDEFGHIJ:<>?@ABCDEFGHIJ:<>?@ABCDEFGHIJ experimental%Patrick Perry <patperry@stanford.edu>5A mutable permutation that can be manipulated in the K monad. The  type argument s( is the state variable argument for the K type. L%The immutable permutation data type. # Internally, a permutation of size n is stored as an  0-based array of n M/s. The permutation represents a reordering of  the integers  0, ..., (n-1). The ith element of the array stores  the value p[i]. N!Get the size of the permutation. (Get a list of the permutation elements. OPQRSTUVWXYLNOPQRSTUVWXYLLNNOPQRSTUVWXY experimental%Patrick Perry <patperry@stanford.edu> 5A mutable permutation that can be manipulated in the Z monad. The  type argument s( is the state variable argument for the Z type. [\]^_`abcdef [\]^_`abcdef [[\]^_`abcdef experimental%Patrick Perry <patperry@stanford.edu>(IClass for representing a mutable permutation. The type is parameterized  over the type of the monad, m+, in which the mutable permutation will be  manipulated. Get the size of a permutation. 9Create a new permutation initialized to be the identity. 5Allocate a new permutation but do not initialize it. FGet a lazy list of the permutation elements. The laziness makes this C function slightly dangerous if you are modifying the permutation. =Set all the values of a permutation from a list of elements. g3Construct a permutation from a list of elements.  newListPermute n is creates a permuation of size n with  the ith element equal to is !! i$. For the permutation to be valid,  the list is must have length n and contain the indices 0..(n-1)  exactly once each. .Construct a permutation from a list of swaps.  newSwapsPermute n ss creates a permuation of size n given a  sequence of swaps.  If ss is [(i0,j0), (i1,j1), ..., (ik,jk)], the  sequence of swaps is  i0 <-> j0, then  i1 <-> j1, and so on until  ik <-> jk. h0Construct a new permutation by copying another. copyPermute dst src( copies the elements of the permutation src  into the permtuation dst+. The two permutations must have the same  size. #Set a permutation to the identity.  getElem p i gets the value of the ith element of the permutation  p . The index i must be in the range 0..(n-1), where n is the  size of the permutation.  setElem p i x sets the value of the ith element of the permutation  p . The index i must be in the range 0..(n-1), where n is the  size of the permutation. swapElems p i j exchanges the ith and jth elements of the  permutation p. FReturns whether or not the permutation is valid. For it to be valid,  the numbers  0,...,(n-1), must all appear exactly once in the stored  values p[0] ,...,p[n-1]. (Compute the inverse of a permutation. 4Set one permutation to be the inverse of another.  copyInverse inv p computes the inverse of p and stores it in inv. / The two permutations must have the same size. HAdvance a permutation to the next permutation in lexicogrphic order and  return True4. If no further permutaitons are available, return False and L leave the permutation unmodified. Starting with the idendity permutation  and repeatedly calling setNext- will iterate through all permutations of a  given size. FStep backwards to the previous permutation in lexicographic order and  return True/. If there is no previous permutation, return False and # leave the permutation unmodified. i EGet a lazy list of swaps equivalent to the permutation. A result of  ![ (i0,j0), (i1,j1), ..., (ik,jk) ] means swap i0 <-> j0,  then i1 <-> j1, and so on until ik <-> jk. The laziness makes this C function slightly dangerous if you are modifying the permutation. !EGet a lazy list of swaps equivalent to the inverse of a permutation. j"3Convert a mutable permutation to an immutable one. #3Convert an immutable permutation to a mutable one. $ getSort n xs sorts the first n elements of xs and returns a  permutation which transforms xs% into sorted order. The results are  undefined if n is greater than the length of xs. This is a special  case of %. %& getOrder n xs2 returns a permutation which rearranges the first n  elements of xs4 into ascending order. The results are undefined if n is  greater than the length of xs. This is a special case of '. '( getRank n xs< eturns a permutation, the inverse of which rearranges the  first n elements of xs2 into ascending order. The returned permutation,  p, has the property that p[i] is the rank of the ith element of xs.  The results are undefined if n is greater than the length of xs.  This is a special case of ). )$  !"#$%&'()$  !$%&'()"#$    !"#$%&'() experimental%Patrick Perry <patperry@stanford.edu>*KA safe way to create and work with a mutable permutation before returning O an immutable permutation for later perusal. This function avoids copying the N permutation before returning it - it uses unsafeFreeze internally, but this 0 wrapper is a safe interface to that function. &  !"#$%&'()*** experimental%Patrick Perry <patperry@stanford.edu>%  !"#$%&'() experimental%Patrick Perry <patperry@stanford.edu>+5Construct an identity permutation of the given size. ,3Construct a permutation from a list of elements.  listPermute n is creates a permuation of size n with  the ith element equal to is !! i$. For the permutation to be valid,  the list is must have length n and contain the indices 0..(n-1)  exactly once each. -.Construct a permutation from a list of swaps.  swapsPermute n ss creats a permuation of size n given by a  sequence of swaps.  If ss is [(i0,j0), (i1,j1), ..., (ik,jk)], the  sequence of swaps is  i0 <-> j0, then  i1 <-> j1, and so on until  ik <-> jk. . apply p i gets the value of the ith element of the permutation  p . The index i must be in the range 0..(n-1), where n is the  size of the permutation. /!Get the inverse of a permutation 07Return the next permutation in lexicographic order, or Nothing if L there are no further permutations. Starting with the identity permutation L and repeatedly calling this function will iterate through all permutations  of a given order. 1;Return the previous permutation in lexicographic order, or Nothing " if there is no such permutation. k2@Get a list of swaps equivalent to the permutation. A result of  ![ (i0,j0), (i1,j1), ..., (ik,jk) ] means swap i0 <-> j0,  then i1 <-> j1, and so on until ik <-> jk. 3>Get a list of swaps equivalent to the inverse of permutation. 4 sort n xs sorts the first n elements of xs and returns a  permutation which transforms xs% into sorted order. The results are  undefined if n is greater than the length of xs. This is a special  case of 5. 56 order n xs2 returns a permutation which rearranges the first n  elements of xs4 into ascending order. The results are undefined if n is  greater than the length of xs. This is a special case of 7. 78 rank n xs< eturns a permutation, the inverse of which rearranges the  first n elements of xs2 into ascending order. The returned permutation,  p, has the property that p[i] is the rank of the ith element of xs.  The results are undefined if n is greater than the length of xs.  This is a special case of 9. 9+,-./0123456789+,-./0123456789+,-./0123456789l      !"#$%&'()*+,-./0123456789:;<=>?@ABBCCDE FGHIJKLMNOPQRS TUVWXYZ[\]^QR_ `abcdefghijklmnoppermutation-0.2.1Data.Permute.ST Data.PermuteData.Permute.IOData.Permute.MPermute Data.IntArrayData.Permute.BaseData.Permute.IOBase STPermutePermute unsafeApplysizeelems IOPermuteMPermutegetSize newPermute newPermute_ unsafeGetElem unsafeSetElemunsafeSwapElemsgetElemssetElems unsafeFreeze unsafeThawnewListPermuteunsafeNewListPermutenewSwapsPermuteunsafeNewSwapsPermutenewCopyPermute copyPermute setIdentitygetElemsetElem swapElemsisValid getInverse copyInversesetNextsetPrevgetSwaps getInvSwapsfreezethawgetSort getSortBygetOrder getOrderBygetRank getRankBy runSTPermutepermute listPermute swapsPermuteapplyinversenextprevswapsinvSwapssortsortByorderorderByrankrankBy STIntArrayIntArray numElementsunsafeAt newArray_numElementsSTIntArraygetNumElements unsafeRead unsafeWrite unsafeSwap readElems writeElemsbaseGHC.STSTghc-prim GHC.TypesIntgetSizeSTPermute sizeSTPermute newSTPermute newSTPermute_unsafeGetElemSTPermuteunsafeSetElemSTPermuteunsafeSwapElemsSTPermutegetElemsSTPermutesetElemsSTPermuteunsafeFreezeSTPermuteunsafeThawSTPermuteIO newIOPermute newIOPermute_getSizeIOPermute sizeIOPermuteunsafeGetElemIOPermuteunsafeSetElemIOPermuteunsafeSwapElemsIOPermutegetElemsIOPermutesetElemsIOPermuteunsafeFreezeIOPermuteunsafeThawIOPermuteunsafeInterleaveMnewSwapsPermuteHelp setNextBy getSwapsHelp nextPrevHelp