Class SublistGenerator

java.lang.Object
edu.cmu.tetrad.util.SublistGenerator

public final class SublistGenerator extends Object
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

    Constructors
    Constructor
    Description
    SublistGenerator(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 Type
    Method
    Description
    int
    Getter for the field a.
    static int
    getNumCombinations(int a, int b)
    getNumCombinations.
    int[]
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 int
      b - 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

      public String toString()

      toString.

      Overrides:
      toString in class Object
      Returns:
      a String object
    • getA

      public int getA()

      Getter for the field a.

      Returns:
      Ibid.