cc.redberry.core.combinatorics
Class IntCombinationsGenerator
- java.lang.Object
-
- cc.redberry.core.combinatorics.IntCombinatorialGenerator
-
- cc.redberry.core.combinatorics.IntCombinationsGenerator
-
- All Implemented Interfaces:
- IntCombinatorialPort, OutputPort<int[]>, java.lang.Iterable<int[]>, java.util.Iterator<int[]>
public final class IntCombinationsGenerator extends IntCombinatorialGenerator implements IntCombinatorialPort
This class represents an iterator over all unordered combinations (i.e. [0,1] and [1,0] are considered as same, so only [0,1] will appear in the sequence) ofknumbers, which can be chosen from the set ofnnumbers (0,1,2,...,n). The total number of such combinations is a binomial coefficientn!/(k!(n-k)!). Each returned array is sorted.The iterator is implemented such that each next combination will be calculated only on the invocation of method
next().Note: method
next()returns the same reference on each invocation. So, if it is needed not only to obtain the information fromnext(), 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 IntCombinationsGenerator(int n, int k)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int[]getReference()Returns the reference on the current iteration element.booleanhasNext()int[]next()voidremove()voidreset()Resets the iterationint[]take()Calculates and returns the next combination or null, if no more combinations exist.-
Methods inherited from class cc.redberry.core.combinatorics.IntCombinatorialGenerator
iterator
-
-
-
-
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
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<int[]>
-
reset
public void reset()
Description copied from class:IntCombinatorialGeneratorResets the iteration- Specified by:
resetin interfaceIntCombinatorialPort- Specified by:
resetin classIntCombinatorialGenerator
-
next
public int[] next()
- Specified by:
nextin interfacejava.util.Iterator<int[]>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<int[]>- Throws:
java.lang.UnsupportedOperationException- always
-
getReference
public int[] getReference()
Description copied from class:IntCombinatorialGeneratorReturns the reference on the current iteration element.- Specified by:
getReferencein interfaceIntCombinatorialPort- Specified by:
getReferencein classIntCombinatorialGenerator- Returns:
- the reference on the current iteration element
-
-
DataMelt 3.0 © DataMelt by jWork.ORG