cc.redberry.core.combinatorics
Class IntDistinctTuplesPort
- java.lang.Object
-
- cc.redberry.core.combinatorics.IntDistinctTuplesPort
-
- All Implemented Interfaces:
- IntCombinatorialPort, OutputPort<int[]>
public class IntDistinctTuplesPort extends java.lang.Object implements IntCombinatorialPort
This class represents an iterator (implemented in the output port pattern) over all distinct N-tuples, which can be chosen fromNsets of integers. More formally, forNinteger 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}; DistinctCombinationsPort dcp = new DistinctCombinationsPort(a1, a2); int[] tuple; while ((tuple = dcp.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. So, if it is needed not only to obtain the information fromtake(), but also save the result, it is necessary to clone the returned array.- Since:
- 1.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cc.redberry.core.utils.OutputPort
OutputPort.PortIterable<T>, OutputPort.PortIterator<T>, OutputPort.Singleton<T>
-
-
Constructor Summary
Constructors Constructor and Description IntDistinctTuplesPort(int[]... sets)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int[]getReference()Returns the reference to the current iteration element.voidreset()Resets the iterationint[]take()Calculates and returns the next tuple, ornullif no more distinct tuples exist.
-
-
-
Method Detail
-
take
public int[] take()
Calculates and returns the next tuple, ornullif no more distinct tuples exist.- Specified by:
takein interfaceIntCombinatorialPort- Specified by:
takein interfaceOutputPort<int[]>- Returns:
- the next tuple, or
nullif no more distinct tuples exist
-
reset
public void reset()
Description copied from interface:IntCombinatorialPortResets the iteration- Specified by:
resetin interfaceIntCombinatorialPort
-
getReference
public int[] getReference()
Description copied from interface:IntCombinatorialPortReturns the reference to the current iteration element.- Specified by:
getReferencein interfaceIntCombinatorialPort- Returns:
- the reference to the current iteration element
-
-
DataMelt 3.0 © DataMelt by jWork.ORG