cc.redberry.core.combinatorics
Class IntCombinationPermutationGenerator
- java.lang.Object
-
- cc.redberry.core.combinatorics.IntCombinatorialGenerator
-
- cc.redberry.core.combinatorics.IntCombinationPermutationGenerator
-
- All Implemented Interfaces:
- IntCombinatorialPort, OutputPort<int[]>, java.lang.Iterable<int[]>, java.util.Iterator<int[]>
public final class IntCombinationPermutationGenerator extends IntCombinatorialGenerator implements IntCombinatorialPort
This class represents an 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. So, if it is needed not only to obtain the information fromnext(), but also to save the result, it is necessary to clone the returned array!Inner implementation of this class is simply uses the combination of
IntCombinationsGeneratorandIntPermutationsGenerator.- Since:
- 1.0
- See Also:
IntCombinationsGenerator,IntPermutationsGenerator
-
-
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 IntCombinationPermutationGenerator(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()Calculates and returns the next combination.voidremove()Throws UnsupportedOperationException.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
-
-
-
-
Constructor Detail
-
IntCombinationPermutationGenerator
public IntCombinationPermutationGenerator(int n, int k)
-
-
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[]>
-
next
public int[] next()
Calculates and returns the next combination.- Specified by:
nextin interfacejava.util.Iterator<int[]>- Returns:
- the next combination
-
remove
public void remove()
Throws UnsupportedOperationException.- Specified by:
removein interfacejava.util.Iterator<int[]>
-
reset
public void reset()
Description copied from class:IntCombinatorialGeneratorResets the iteration- Specified by:
resetin interfaceIntCombinatorialPort- Specified by:
resetin classIntCombinatorialGenerator
-
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