public class CompoundPermutationIter extends java.lang.Object implements ArrayPermutationsIter, java.util.Iterator
These are the possible compound perm: [$,1,2,a,b,c]
[$,1,2,a,c,b]
[$,1,2,b,a,c]
[$,1,2,b,c,a]
[$,1,2,c,a,b]
[$,1,2,c,b,a]
[$,2,1,a,b,c]
[$,2,1,a,c,b]
[$,2,1,b,a,c]
[$,2,1,b,c,a]
[$,2,1,c,a,b]
[$,2,1,c,b,a]
The overall number is the product of the factorials of each eq. group size; in our example : (1!)x(2!)x(3!)=1x2x6=12. Using the constructor with eq.group sizes and initial order [1,2,3], the result permutations are retrieved as numbers in an array, where [0,1,2,3,4,5] means [$,1,2,a,b,c]:
[0,1,2,3,5,4]
[0,1,2,4,3,5]
etc. etc., till:
[0,2,1,5,4,3] means [$,2,1,c,b,a]
Performance: The implementation tries to advance each time the group zero, if it does not succeed, it tries the next group (1,2 and so on), so: try to put the largest group as the first groups, UNLIKE the example. Performance-wise it is better to do [a,b,c,1,2,$] .The effect is improvement by constant (for example, by 2)
Constructor and Description |
---|
CompoundPermutationIter(int[] equalityGroupsSizesArray)
For the class example, use [1,2,2].
|
Modifier and Type | Method and Description |
---|---|
int |
getMax() |
int[] |
getNext()
Iteration may be one of these two: 1.
|
int[] |
getPermAsArray()
Creates and returns a new array which consists of the eq.
|
boolean |
hasNext() |
boolean |
hasNextPermutaions() |
java.lang.Object |
next() |
int[] |
nextPermutation() |
void |
remove()
UNIMPLEMENTED.
|
public CompoundPermutationIter(int[] equalityGroupsSizesArray)
equalityGroupsSizesArray
- public java.lang.Object next()
next
in interface java.util.Iterator
public int[] getNext()
public int[] getPermAsArray()
public boolean hasNext()
hasNext
in interface java.util.Iterator
public int getMax()
public int[] nextPermutation()
nextPermutation
in interface ArrayPermutationsIter
public boolean hasNextPermutaions()
hasNextPermutaions
in interface ArrayPermutationsIter
public void remove()
remove
in interface java.util.Iterator
Iterator.remove()