cc.redberry.core.combinatorics
Class IntTuplesPort
- java.lang.Object
-
- cc.redberry.core.combinatorics.IntTuplesPort
-
- All Implemented Interfaces:
- IntCombinatorialPort, OutputPort<int[]>
public final class IntTuplesPort extends java.lang.Object implements IntCombinatorialPort
This class allows to iterate over all N-tuples (not necessary to be distinct), which can be chosen fromNarrays of integers of the form arrayi = [0, 1, 2, ..., Ki].
For example, if a set of arrays length is {Ki} = [2,3,2], then the following tuples will be producedarr lastUpdateDepth [0, 0, 0] 0 [0, 0, 1] 2 [0, 1, 0] 1 [0, 1, 1] 2 [0, 2, 0] 1 [0, 2, 1] 2 [1, 0, 0] 0 [1, 0, 1] 2 [1, 1, 0] 1 [1, 1, 1] 2 [1, 2, 0] 1 [1, 2, 1] 2This 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 IntTuplesPort(int... upperBounds)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetLastUpdateDepth()int[]getReference()Returns the reference to the current iteration element.voidreset()Resets the iterationint[]take()Calculates and returns the next combination or null, if no more combinations exist.
-
-
-
Method Detail
-
take
public int[] take()
Description copied from interface:IntCombinatorialPortCalculates and returns the next combination or null, if no more combinations exist.- Specified by:
takein interfaceIntCombinatorialPort- Specified by:
takein interfaceOutputPort<int[]>- Returns:
- the next combination or null, if no more combinations exist
-
getLastUpdateDepth
public int getLastUpdateDepth()
-
reset
public void reset()
Resets 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