public final class IntDistinctTuples extends Object implements IntCombinatorialPort
N sets of integers. More formally, for N integer arrays: array1, array2,...,arrayN, this class allows
to iterate over all possible integer arrays of the form [i1, i2,...,iN], where all
numbers numbers ij are different and i1 is chosen from array1, i2
is chosen from array2 and so on.
Consider the example:
This code will produce the following sequence:
int[] a1 = {1, 2, 3};
int[] a2 = {2, 3};
IntDistinctTuples tuples = new IntDistinctTuples(a1, a2);
int[] tuple;
while ((tuple = tuples.take()) != null)
System.out.println(Arrays.toString(tuple));
[1, 2]
[1, 3]
[2, 3]
[3, 2]
This class is implemented via output port pattern and the calculation of the next tuple occurs only on the
invocation of take().
Note: method take() returns the same reference on each invocation.
IntCombinatorialPort.Iterator| Constructor and Description |
|---|
IntDistinctTuples(int[]... sets)
Create iterator over distinct tuples formed from the specified arrays (each set will be sorted in place)
|
| Modifier and Type | Method and Description |
|---|---|
int[] |
getReference()
Returns the reference to the current iteration element
|
void |
reset()
Resets the iteration
|
int[] |
take()
Calculates and returns the next tuple, or
null if no more distinct tuples exist. |
public IntDistinctTuples(int[]... sets)
public int[] take()
null if no more distinct tuples exist.take in interface IntCombinatorialPortnull if no more distinct tuples existpublic void reset()
IntCombinatorialPortreset in interface IntCombinatorialPortpublic int[] getReference()
IntCombinatorialPortgetReference in interface IntCombinatorialPortCopyright © 2017. All rights reserved.