Class Combinations.LexicographicIterator
java.lang.Object
org.apache.commons.math3.util.Combinations.LexicographicIterator
- All Implemented Interfaces:
Iterator<int[]>
- Enclosing class:
Combinations
Lexicographic combinations iterator.
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.
- Since:
- 3.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]c[1], ..., c[k] stores the next combination; c[k + 1], c[k + 2] are sentinels.private intMarker: smallest index such that c[j + 1] > jprivate final intSize of subsets returned by the iteratorprivate booleanReturn value forhasNext() -
Constructor Summary
ConstructorsConstructorDescriptionLexicographicIterator(int n, int k) Construct a CombinationIterator to enumerate k-sets from n. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
Field Details
-
k
private final int kSize of subsets returned by the iterator -
c
private final int[] cc[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.
-
more
private boolean moreReturn value forhasNext() -
j
private int jMarker: smallest index such that c[j + 1] > j
-
-
Constructor Details
-
LexicographicIterator
LexicographicIterator(int n, int k) Construct a CombinationIterator to enumerate k-sets from n.NOTE: If
k === 0ork >= n, the Iterator will be empty (that is,hasNext()will returnfalseimmediately.- Parameters:
n- size of the set from which subsets are enumeratedk- size of the subsets to enumerate
-
-
Method Details
-
hasNext
-
next
-
remove
-