Package cc.redberry.combinatorics
Class IntCombinations
- java.lang.Object
-
- cc.redberry.combinatorics.IntCombinatorialIterator
-
- cc.redberry.combinatorics.IntCombinations
-
- All Implemented Interfaces:
CombinatorialIterator<int[]>,java.io.Serializable,java.lang.Iterable<int[]>,java.util.Iterator<int[]>
public final class IntCombinations extends IntCombinatorialIterator
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.- Since:
- 1.0
- See Also:
IntCombinationsWithPermutations, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int[]combinationprivate intkprivate intnprivate booleanonFirstprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description IntCombinations(int n, int k)Constructs the iterator with the desired n and k
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]current()Returns the reference on the current iteration element.booleanhasNext()private booleanisLast()int[]next()voidremove()voidreset()Resets the iteration-
Methods inherited from class cc.redberry.combinatorics.IntCombinatorialIterator
toList
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cc.redberry.combinatorics.CombinatorialIterator
iterator, stream
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
combination
final int[] combination
-
n
private final int n
-
k
private final int k
-
onFirst
private boolean onFirst
-
-
Method Detail
-
hasNext
public boolean hasNext()
-
reset
public void reset()
Description copied from interface:CombinatorialIteratorResets the iteration
-
isLast
private boolean isLast()
-
next
public int[] next()
-
remove
public void remove()
- Throws:
java.lang.UnsupportedOperationException- always
-
current
public int[] current()
Description copied from interface:CombinatorialIteratorReturns the reference on the current iteration element.- Returns:
- the reference on the current iteration element
-
-