Package org.apache.commons.math3.util
Class Combinations.LexicographicComparator
java.lang.Object
org.apache.commons.math3.util.Combinations.LexicographicComparator
- All Implemented Interfaces:
Serializable,Comparator<int[]>
- Enclosing class:
Combinations
private static class Combinations.LexicographicComparator
extends Object
implements Comparator<int[]>, Serializable
Defines the lexicographic ordering of combinations, using
the
lexNorm(int[]) method.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intNumber of elements in each combination.private final intSize of the set from which combinations are drawn.private static final longSerializable version identifier. -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerializable version identifier.- See Also:
-
n
private final int nSize of the set from which combinations are drawn. -
k
private final int kNumber of elements in each combination.
-
-
Constructor Details
-
LexicographicComparator
LexicographicComparator(int n, int k) - Parameters:
n- Size of the set from which subsets are selected.k- Size of the subsets to be enumerated.
-
-
Method Details
-
compare
public int compare(int[] c1, int[] c2) - Specified by:
comparein interfaceComparator<int[]>- Throws:
DimensionMismatchException- if the array lengths are not equal tok.OutOfRangeException- if an element of the array is not within the interval [0,n).
-
lexNorm
private long lexNorm(int[] c) Computes the value (in base 10) represented by the digit (interpreted in basen) in the input array in reverse order. For example ifcis{3, 2, 1}, andnis 3, the method will return 18.- Parameters:
c- Input array.- Returns:
- the lexicographic norm.
- Throws:
OutOfRangeException- if an element of the array is not within the interval [0,n).
-