Package cc.redberry.combinatorics
Class IntCompositions
- java.lang.Object
-
- cc.redberry.combinatorics.IntCompositions
-
- All Implemented Interfaces:
IntCombinatorialPort,java.io.Serializable
public final class IntCompositions extends java.lang.Object implements IntCombinatorialPort
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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cc.redberry.combinatorics.IntCombinatorialPort
IntCombinatorialPort.Iterator
-
-
Field Summary
Fields Modifier and Type Field Description private int[]arrayprivate IntCombinationsgeneratorprivate intintegerprivate intnCompositionsprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description IntCompositions(int integer, int nCompositions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]getReference()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 Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
integer
private final int integer
-
nCompositions
private final int nCompositions
-
generator
private final IntCombinations generator
-
array
private int[] array
-
-
Method Detail
-
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
-
-