All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.monsterworks.utils.Permuter



java.lang.Object
   |
   +----com.monsterworks.utils.Permuter

public class Permuter
extends java.lang.Object
This class implements a mathematical permutation and its inverse. It is primarily useful when you want to randomly order a collection of integers. It will usually be used as a filter in order to permute an array, indices returned from the array will be "permuted" and indices passed back to the array will be "unpermuted". Currently this class is designed with runtime speed as a priority over run-time space, hence it may be unsuitable for large arrays in tight memory situations.

Version:
1.0b1
Author:
Aaron Montgomery

Constructor Index

 o Permuter(boolean, int)
This method constructs a Permuter which is the identity.
 o Permuter(int)
This method constructs a Permuter which works on arrays of a fixed size.

Method Index

 o length()
This method returns the size of the array on which the Permuter can work.
 o permute(int)
This method returns the permuted position of the input and is the inverse function for unPermute.
 o swap(int, int)
This method is used to swap elements in the permutation.
 o toString()
This method returns the permutation as a list of integers.
 o unPermute(int)
This method returns the actual position of the input and is the inverse function of permute.

Constructors

 o Permuter


 public Permuter(int inSize)
This method constructs a Permuter which works on arrays of a fixed size. All subclass constructors should take an integer as their first argument (to distinguish them from internal protected/private constructors).

Parameters:
inSize - the size of array on which this Permuter will work
 o Permuter


 protected Permuter(boolean inDummy,
                    int inSize)
This method constructs a Permuter which is the identity. Although this is pretty useless, it provides the possibility of subclasses creating specific permutations via the swap method.

Parameters:
inDummy - this parameter is not used but distinguishes this permuter from the public version

Methods

 o permute


 public int permute(int inInteger)
This method returns the permuted position of the input and is the inverse function for unPermute.

Parameters:
inInteger - the integer which needs to be permuted
Returns:
the position to which the integer was permuted
See Also:
unPermute
 o unPermute


 public int unPermute(int inInteger)
This method returns the actual position of the input and is the inverse function of permute.

Parameters:
inInteger - the position in the permutation
Returns:
the integer placed in this position
See Also:
permute
 o length


 public int length()
This method returns the size of the array on which the Permuter can work.

Returns:
the length of the arrays on which the permuter works
 o toString


 public java.lang.String toString()
This method returns the permutation as a list of integers. The first integer is the result of permute(0), the second of permute(1) and so forth.

Returns:
the string representation of the permutation
Overrides:
toString in class java.lang.Object
 o swap


 protected void swap(int inIndexOne,
                     int inIndexTwo)
This method is used to swap elements in the permutation. It is primarily used with the protected constructor in order to generate specific permutations. Mathematically, swap(inIndexOne, inIndexTwo) is the result of first permuting (1,2) and then the original permutation.

Parameters:
inIndexOne - the index of the first location to be swapped
inIndexTwo - the index of the second location to be swapped



All Packages  Class Hierarchy  This Package  Previous  Next  Index