Package cc.redberry.combinatorics
Class IntCompositions
java.lang.Object
cc.redberry.combinatorics.IntCompositions
- All Implemented Interfaces:
IntCombinatorialPort,Serializable
Iterator over all compositions of specified integer into N parts.
Implementation note: the description of the algorithm can be found here https://stackoverflow.com/a/6609080/946635
- Since:
- 2.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 final IntCombinationsprivate final intprivate final intprivate static final long -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
integer
private final int integer -
nCompositions
private final int nCompositions -
generator
-
array
private int[] array
-
-
Constructor Details
-
IntCompositions
public IntCompositions(int integer, int nCompositions)
-
-
Method Details
-
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
-
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
-