Package edu.cmu.tetrad.util
Class SublistGenerator
java.lang.Object
edu.cmu.tetrad.util.SublistGenerator
Generates (nonrecursively) all of the sublists of size b from a list of size a, where a, b are nonnegative integers
and a >= b. The values of a and b are given in the constructor, and the sequence of sublists is obtained by
repeatedly calling the next() method. When the sequence is finished, null is returned.
A valid combination for the sublists generated by this class is an array x[] of b integers i, 0 <= i < a, such that x[j] < x[j + 1] for each j from 0 to b - 1.
Works by calling ChoiceGenerator with increasingly larger values of a.
To see what this class does, try calling ChoiceGenerator.testPrint(5, 3), for instance.
- Version:
- $Id: $Id
- Author:
- josephramsey
-
Constructor Summary
ConstructorsConstructorDescriptionSublistGenerator
(int a, int depth) Constructs a new generator for sublists for a list of size b taken a at a time. -
Method Summary
Modifier and TypeMethodDescriptionint
getA()
Getter for the fielda
.static int
getNumCombinations
(int a, int b) getNumCombinations.int[]
next()
next.static void
testPrint
(int a, int depth) This static method will print the series of combinations for a choose depth to System.out.toString()
toString.
-
Constructor Details
-
SublistGenerator
public SublistGenerator(int a, int depth) Constructs a new generator for sublists for a list of size b taken a at a time. Once this initialization has been performed, successive calls to next() will produce the series of combinations. To begin a new series at any time, call this init method again with new values for a and b.- Parameters:
a
- the size of the list being selected from.depth
- the maximum number of elements selected.
-
-
Method Details
-
getNumCombinations
public static int getNumCombinations(int a, int b) getNumCombinations.
- Parameters:
a
- a intb
- a int- Returns:
- a int
-
testPrint
public static void testPrint(int a, int depth) This static method will print the series of combinations for a choose depth to System.out.- Parameters:
a
- the number of objects being selected from.depth
- the number of objects in the desired selection.
-
next
public int[] next()next.
- Returns:
- the next combination in the series, or null if the series is finished.
-
toString
-
getA
public int getA()Getter for the field
a
.- Returns:
- Ibid.
-