Package org.gorpipe.gor.gava
Class CombinationIterator
java.lang.Object
org.gorpipe.gor.gava.CombinationIterator
Iterate through all combinations (n choose k) and provide permutations representing the combinations.
Designed to work in permutation tests, where instead of randomization all combinations are tested.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublegetNumberOfCombinations(int n, int k) Computes the number of combinations.int[]booleannext()Advance to the next combination.
-
Constructor Details
-
CombinationIterator
public CombinationIterator(int totalCount, int subCount) Instantiate the iterator.- Parameters:
totalCount- the total number of elementssubCount- the number of elements to choose
-
-
Method Details
-
getPermutation
public int[] getPermutation()- Returns:
- a permutation representing the combination
-
next
public boolean next()Advance to the next combination. (First call stays in the initial combination.)- Returns:
- true if there is a next combination
-
getNumberOfCombinations
public static double getNumberOfCombinations(int n, int k) Computes the number of combinations. Returns a double because rounding to int will cause undesired results when the number is larger than max int.- Parameters:
n- total countk- sub count- Returns:
- the number of combinations (n choose k)
-