|
|||||||||
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.CartesianProduct<T>
T
- The type of the elements one wants the cartesian product of.public class CartesianProduct<T>
A class that sequentially returns the cartesian product of sets, represented as a two-dimensional array. TODO: incorporate this into my CombinatoricOperator frame.
Field Summary | |
---|---|
protected T[][] |
elements
The elements the operator works upon. |
protected int[] |
indices
An integer array backing up the original one to keep track of the indices. |
private int |
numLeft
The variations still to go. |
private int |
total
The total number of variations to be computed. |
Constructor Summary | |
---|---|
CartesianProduct(T[][] elements)
Initialize a new operator, with given elements and size of the arrays to be returned. |
Method Summary | |
---|---|
protected void |
computeNext()
Compute the next array of indices. |
int |
getNumLeft()
Return number of variations not yet generated. |
private T[] |
getResult(int[] indexes)
Compute the result, based on the given array of indices. |
int |
getTotal()
Return the total number of variations. |
boolean |
hasNext()
Returns true if the iteration has more elements. |
protected void |
initializeIndices()
Initialize the array of indices. |
protected int |
initializeTotal()
Compute the total number of elements to return. |
java.util.Iterator<T[]> |
iterator()
A combinatoric operator is itself an iterator. |
T[] |
next()
Compute the next combination. |
void |
remove()
Not supported. |
void |
reset()
Reset the iteration. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected T[][] elements
protected int[] indices
private int numLeft
private final int total
Constructor Detail |
---|
public CartesianProduct(T[][] elements)
elements
- The elements on which this combinatoric operator has to act.| let sum =
BigInteger.ONE
| for 0 <= i < elements.length | sum.multiply(elements[i].length) | new.getTotal() == sum
| new.getNumLeft() == new.getTotal()
Method Detail |
---|
protected void initializeIndices()
protected int initializeTotal()
| result >= 0
public void reset()
| new.getNumLeft() ==
getTotal()
public int getNumLeft()
public int getTotal()
public boolean hasNext()
hasNext
in interface java.util.Iterator<T[]>
| result == getNumLeft().compareTo(BigInteger.ZERO) >
0;
public T[] next()
next
in interface java.util.Iterator<T[]>
protected void computeNext()
private T[] getResult(int[] indexes)
indexes
- An array of indices into the element array.| result[i] == elements[indexes[i]]
public void remove()
remove
in interface java.util.Iterator<T[]>
public java.util.Iterator<T[]> iterator()
iterator
in interface java.lang.Iterable<T[]>
| result == this
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |