| Modifier and Type | Class and Description |
|---|---|
| private static enum | Combinations.
Describes the type of iteration performed by the
|
| private static class | Combinations.
Defines the lexicographic ordering of combinations, using
the |
| private static class | Combinations.
Lexicographic combinations iterator. |
| private static class | Combinations.
Iterator with just one element to handle degenerate cases (full array, empty array) for combination iterator. |
| Modifier and Type | Field and Description |
|---|---|
| private final Combinations. | iterationOrder
Iteration order. |
| private final int | k
Number of elements in each combination. |
| private final int | n
Size of the set from which combinations are drawn. |
| Access | Constructor and Description |
|---|---|
| public | Combinations(int
Size of the set from which subsets are selected. n, int Size of the subsets to be enumerated. k)Creates an instance whose range is the k-element subsets of
{0, ..., n - 1} represented as |
| private | Combinations(int
Size of the set from which subsets are selected. n, int Size of the subsets to be enumerated. k, Combinations.Specifies the iterationOrderiteration order.Creates an instance whose range is the k-element subsets of
{0, ..., n - 1} represented as |
| Modifier and Type | Method and Description |
|---|---|
| public Comparator | |
| public int | Returns: the size of the subsets to be enumerated.Gets the number of elements in each combination. |
| public int | |
| public Iterator |
| iterationOrder | back to summary |
|---|---|
| private final Combinations. Iteration order. | |
| k | back to summary |
|---|---|
| private final int k Number of elements in each combination. | |
| n | back to summary |
|---|---|
| private final int n Size of the set from which combinations are drawn. | |
| Combinations | back to summary |
|---|---|
| public Combinations(int n, int k) Creates an instance whose range is the k-element subsets of
{0, ..., n - 1} represented as
The iteration order is lexicographic: the arrays returned by the
k == 0 an iterator containing an empty array is returned;
if k == n an iterator containing [0, ..., n - 1] is returned.
| |
| Combinations | back to summary |
|---|---|
| private Combinations(int n, int k, Combinations. Creates an instance whose range is the k-element subsets of
{0, ..., n - 1} represented as
If the k == 0 an iterator containing an empty array is returned;
if k == n an iterator containing [0, ..., n - 1] is returned.
| |
| comparator | back to summary |
|---|---|
| public Comparator Defines a lexicographic ordering of combinations.
The returned comparator allows to compare any two combinations
that can be produced by this instance's
| |
| getK | back to summary |
|---|---|
| public int getK() Gets the number of elements in each combination.
| |
| getN | back to summary |
|---|---|
| public int getN() Gets the size of the set from which combinations are drawn.
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over elements of type
| |
iterator.
| Modifier and Type | Field and Description |
|---|---|
| public static final Combinations. | LEXICOGRAPHIC
Lexicographic order. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static Combinations. | |
| public static Combinations. |
| LEXICOGRAPHIC | back to summary |
|---|---|
| public static final Combinations. Lexicographic order. | |
| IterationOrder | back to summary |
|---|---|
| private IterationOrder() | |
| valueOf | back to summary |
|---|---|
| public static Combinations. | |
| values | back to summary |
|---|---|
| public static Combinations. | |
lexNorm(int[]) method.
| Modifier and Type | Field and Description |
|---|---|
| private final int | k
Number of elements in each combination. |
| private final int | n
Size of the set from which combinations are drawn. |
| private static final long | serialVersionUID
Serializable version identifier. |
| Access | Constructor and Description |
|---|---|
| pack-priv | LexicographicComparator(int
Size of the set from which subsets are selected. n, int Size of the subsets to be enumerated. k)
|
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(int[]
the first object to be compared. c1, int[] the second object to be compared. c2)Implements java. Compares its two arguments for order. |
| private long | Returns: the lexicographic norm.Input array. c)Computes the value (in base 10) represented by the digit
(interpreted in base |
| k | back to summary |
|---|---|
| private final int k Number of elements in each combination. | |
| n | back to summary |
|---|---|
| private final int n Size of the set from which combinations are drawn. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable version identifier. | |
| LexicographicComparator | back to summary |
|---|---|
pack-priv LexicographicComparator(int n, int k)
| |
| compare | back to summary |
|---|---|
| public int compare(int[] c1, int[] c2) Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |
| lexNorm | back to summary |
|---|---|
| private long lexNorm(int[] c) Computes the value (in base 10) represented by the digit
(interpreted in base
| |
Implementation follows Algorithm T in The Art of Computer Programming Internet Draft (PRE-FASCICLE 3A), "A Draft of Section 7.2.1.3 Generating All Combinations, D. Knuth, 2004.
The degenerate cases k == 0 and k == n are NOT handled by this
implementation. If constructor arguments satisfy k == 0
or k >= n, no exception is generated, but the iterator is empty.
| Modifier and Type | Field and Description |
|---|---|
| private final int[] | c
c[1], ..., c[k] stores the next combination; c[k + 1], c[k + 2] are sentinels. |
| private int | j
Marker: smallest index such that c[j + 1] > j |
| private final int | k
Size of subsets returned by the iterator |
| private boolean |
| Access | Constructor and Description |
|---|---|
| pack-priv | LexicographicIterator(int
size of the set from which subsets are enumerated n, int size of the subsets to enumerate k)Construct a CombinationIterator to enumerate k-sets from n. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public int[] | |
| public void |
| c | back to summary |
|---|---|
| private final int[] c c[1], ..., c[k] stores the next combination; c[k + 1], c[k + 2] are sentinels. Note that c[0] is "wasted" but this makes it a little easier to follow the code. | |
| j | back to summary |
|---|---|
| private int j Marker: smallest index such that c[j + 1] > j | |
| k | back to summary |
|---|---|
| private final int k Size of subsets returned by the iterator | |
| more | back to summary |
|---|---|
| private boolean more Return value for | |
| LexicographicIterator | back to summary |
|---|---|
| pack-priv LexicographicIterator(int n, int k) Construct a CombinationIterator to enumerate k-sets from n. Note If
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public int[] next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Not supported. | |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | more
True on initialization, false after first call to next |
| private final int[] | singleton
Singleton array |
| Access | Constructor and Description |
|---|---|
| pack-priv | SingletonIterator(final int[]
array returned by the iterator singleton)Create a singleton iterator providing the given array. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: True until next is called the first time, then falseImplements java. Returns |
| public int[] | Returns: the singleton in first activation; throws NSEE thereafterImplements java. Returns the next element in the iteration. |
| public void |
| more | back to summary |
|---|---|
| private boolean more True on initialization, false after first call to next | |
| singleton | back to summary |
|---|---|
| private final int[] singleton Singleton array | |
| SingletonIterator | back to summary |
|---|---|
| pack-priv SingletonIterator(final int[] singleton) Create a singleton iterator providing the given array.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public int[] next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Not supported | |