Package org.gorpipe.gor.gava
Class CombinationIterator
- java.lang.Object
-
- org.gorpipe.gor.gava.CombinationIterator
-
public class CombinationIterator extends java.lang.ObjectIterate 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 Constructor Description CombinationIterator(int totalCount, int subCount)Instantiate the iterator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static doublegetNumberOfCombinations(int n, int k)Computes the number of combinations.int[]getPermutation()booleannext()Advance to the next combination.
-
-
-
Method Detail
-
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)
-
-