Package cc.redberry.combinatorics
Class IntCombinationsWithPermutations
- java.lang.Object
-
- cc.redberry.combinatorics.IntCombinatorialIterator
-
- cc.redberry.combinatorics.IntCombinationsWithPermutations
-
- All Implemented Interfaces:
CombinatorialIterator<int[]>,java.io.Serializable,java.lang.Iterable<int[]>,java.util.Iterator<int[]>
public final class IntCombinationsWithPermutations extends IntCombinatorialIterator
Iterator over over all possible unique combinations with permutations (i.e. {0,1} and {1,0} both will appear in the iteration) ofknumbers, which can be chosen from the set ofnnumbers (0,1,2,...,n). The total number of such combinations will ben!/(n-k)!.For example, for
k=2andn=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
IntCombinationsandIntPermutations.- Since:
- 1.0
- See Also:
IntCombinations,IntPermutations, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private int[]combinationprivate int[]combinationPermutationprivate IntCombinationscombinationsGeneratorprivate intkprivate int[]permutationprivate IntPermutationspermutationsGeneratorprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description IntCombinationsWithPermutations(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()int[]next()Calculates and returns the next combination.voidremove()Throws UnsupportedOperationException.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
-
permutation
private final int[] permutation
-
combination
private final int[] combination
-
combinationPermutation
private final int[] combinationPermutation
-
permutationsGenerator
private final IntPermutations permutationsGenerator
-
combinationsGenerator
private final IntCombinations combinationsGenerator
-
k
private final int k
-
-
Method Detail
-
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
-
-