Package cc.redberry.combinatorics
Class IntCombinations
java.lang.Object
cc.redberry.combinatorics.IntCombinatorialIterator
cc.redberry.combinatorics.IntCombinations
- All Implemented Interfaces:
CombinatorialIterator<int[]>,Serializable,Iterable<int[]>,Iterator<int[]>
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) of
k numbers, which can be chosen from the set of n numbers (0,1,2,...,n). The
total number of such combinations is a binomial coefficient n!/(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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final int[]private final intprivate final intprivate booleanprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionIntCombinations(int n, int k) Constructs the iterator with the desired n and k -
Method Summary
Methods inherited from class cc.redberry.combinatorics.IntCombinatorialIterator
toListMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface cc.redberry.combinatorics.CombinatorialIterator
iterator, streamMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
combination
final int[] combination -
n
private final int n -
k
private final int k -
onFirst
private boolean onFirst
-
-
Constructor Details
-
IntCombinations
public IntCombinations(int n, int k) Constructs the iterator with the desired n and k
-
-
Method Details
-
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:
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
-