Package cc.redberry.combinatorics
Class IntCombinationsWithPermutations
java.lang.Object
cc.redberry.combinatorics.IntCombinatorialIterator
cc.redberry.combinatorics.IntCombinationsWithPermutations
- All Implemented Interfaces:
CombinatorialIterator<int[]>,Serializable,Iterable<int[]>,Iterator<int[]>
Iterator over over all possible unique combinations with permutations (i.e. {0,1} and {1,0} both will appear in the
iteration) of
k numbers, which can be chosen from the set of n numbers (0,1,2,...,n). The
total number of such combinations will be n!/(n-k)!.
For example, for k=2 and n=3, it will produce the following arrays sequence: [0,1], [1,0], [0,2],
[2,0], [1,2], [2,1].
The iterator is implemented such that each next combination will be calculated only on the invocation of method
next() (no pre-calculation of results).
Note: method next() returns the same reference on each invocation.
Internally this class uses combination of IntCombinations and IntPermutations.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]private final int[]private final IntCombinationsprivate final intprivate final int[]private final IntPermutationsprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionIntCombinationsWithPermutations(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:
-
permutation
private final int[] permutation -
combination
private final int[] combination -
combinationPermutation
private final int[] combinationPermutation -
permutationsGenerator
-
combinationsGenerator
-
k
private final int k
-
-
Constructor Details
-
IntCombinationsWithPermutations
public IntCombinationsWithPermutations(int n, int k) Constructs the iterator with the desired n and k
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
public int[] next()Calculates and returns the next combination.- Returns:
- the next combination
-
remove
public void remove()Throws UnsupportedOperationException. -
reset
public void reset()Description copied from interface:CombinatorialIteratorResets the iteration -
current
public int[] current()Description copied from interface:CombinatorialIteratorReturns the reference on the current iteration element.- Returns:
- the reference on the current iteration element
-