|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator<T> de.uni_tuebingen.sfb.lichtenstein.combinatorics.Permuter<T>
T
- The type of the array to be permuted.public final class Permuter<T>
A class that permutes a given array of elements. It is an iterator that returns all permutations, successively. Thanks to Tim Tyler for the original implementation http://mandala.co.uk/permutations/.
Field Summary |
---|
Fields inherited from class de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator |
---|
elements, indices |
Constructor Summary | |
---|---|
Permuter(T[] elements)
Initialize a new permuter, with given array of elements to permute. |
Method Summary | |
---|---|
protected void |
computeNext()
Compute the next array of indices. |
protected int |
initializeTotal(int n,
int r)
Compute the total number of elements to return. |
private void |
swap(int a,
int b)
Swap the elements at positions a and b, both from the index array and from the element array. |
Methods inherited from class de.uni_tuebingen.sfb.lichtenstein.combinatorics.CombinatoricOperator |
---|
collectionToArray, factorial, getNumLeft, getTotal, hasNext, initializeIndices, iterator, next, remove, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Permuter(T[] elements)
elements
- The elements to permute.| new.getTotal() ==
factorial(elements.length)
| new.getNumLeft() == new.getTotal()
Method Detail |
---|
protected int initializeTotal(int n, int r)
initializeTotal
in class CombinatoricOperator<T>
n
- The number of elements the operator works on.r
- The size of the arrays to return.| result == factorial(n)
protected void computeNext()
computeNext
in class CombinatoricOperator<T>
private void swap(int a, int b)
a
- The first index of the elements to be swapped.b
- The second index of the elements to be swapped.| new.indexes[a] = indexes[b] |
new.indexes[b] = indexes[a]
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |