Package cc.redberry.combinatorics
Class IntTuples
java.lang.Object
cc.redberry.combinatorics.IntTuples
- All Implemented Interfaces:
IntCombinatorialPort,Serializable
Iterator over all N-tuples (not necessary to be distinct), which can be chosen from
For example, if a set of arrays length is {Ki} = [2,3,2], then the following tuples will be produced
N arrays 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 produced
arr 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] 2
Calculation of the next tuple occurs only on the invocation of take().
Note: method take() returns the same reference on each invocation.
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface cc.redberry.combinatorics.IntCombinatorialPort
IntCombinatorialPort.Iterator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]private intprivate static final longprivate final int[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckWithException(int[] upperBounds) intint[]Returns the reference to the current iteration elementvoidreset()Resets the iterationint[]take()Calculates and returns the next combination or null, if no more combinations exist.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
upperBounds
private final int[] upperBounds -
current
private int[] current -
lastUpdateDepth
private int lastUpdateDepth
-
-
Constructor Details
-
IntTuples
public IntTuples(int... upperBounds)
-
-
Method Details
-
checkWithException
private static void checkWithException(int[] upperBounds) -
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- 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
-