viewer
Class Permutation

java.lang.Object
  |
  +--viewer.Permutation

public class Permutation
extends java.lang.Object

Utility class for permutations


Field Summary
static int[] factors
          Cache of factorial function up to fact(12) (maximum for int)
 
Constructor Summary
Permutation()
           
 
Method Summary
static long ArrToPerm(int[] arr)
          Parses array and returns permutation that it represents
static int composePerm(int n, int i1, int i2)
          Composes permutations given by indexes
static long composePerm(int n, long p1, long p2)
          Composes two permutations
static int getNthVal(long perm, int n)
          Returns perm(n)
static long IndexToPerm(int n, int index)
          Return permutation by it's index
static boolean isValidPerm(int n, long perm)
          Check if permutation is valid
static void main(java.lang.String[] args)
          Test function for permutations
static int PermToIndex(int n, long perm)
          Get permutation's index
static java.lang.String PermToString(int n, long perm)
          Convert permutation to string
static long setNthVal(long perm, int n, long val)
          Sets perm(n)=val - for building permutations Note: Can create non-valid permutation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factors

public static int[] factors
Cache of factorial function up to fact(12) (maximum for int)

Constructor Detail

Permutation

public Permutation()
Method Detail

PermToIndex

public static int PermToIndex(int n,
                              long perm)
Get permutation's index

Parameters:
n - n
perm - Permutation
Returns:
Index of the permutation

IndexToPerm

public static long IndexToPerm(int n,
                               int index)
Return permutation by it's index

Parameters:
n - n
index - Index of the requested permutation
Returns:
The permutation that is represented be the index

PermToString

public static java.lang.String PermToString(int n,
                                            long perm)
Convert permutation to string

Parameters:
n - n
perm - Permuation
Returns:
String representing the permuation

getNthVal

public static int getNthVal(long perm,
                            int n)
Returns perm(n)

Parameters:
perm - Permutation
n - Index

setNthVal

public static long setNthVal(long perm,
                             int n,
                             long val)
Sets perm(n)=val - for building permutations Note: Can create non-valid permutation

Parameters:
perm - Permutation to change
n - n
val - New value for perm(n)
Returns:
new permutation

ArrToPerm

public static long ArrToPerm(int[] arr)
Parses array and returns permutation that it represents

Parameters:
arr - Array containing permutation
Returns:
Permutation

composePerm

public static long composePerm(int n,
                               long p1,
                               long p2)
Composes two permutations

Parameters:
n - n
p1 - First permutation
p2 - Second permutation
Returns:
Composed permutation (p1*p2)

composePerm

public static int composePerm(int n,
                              int i1,
                              int i2)
Composes permutations given by indexes

Parameters:
n - n
i1 - Index of first permutation
i2 - Index of second permutation
Returns:
Index of the composed permutation

isValidPerm

public static boolean isValidPerm(int n,
                                  long perm)
Check if permutation is valid

Parameters:
n - n
perm - Permutation to check
Returns:
true if permutation is valid, false otherwise

main

public static void main(java.lang.String[] args)
Test function for permutations

Parameters:
args -