Package org.apache.commons.math3.util
Class Combinations.LexicographicComparator
- java.lang.Object
-
- org.apache.commons.math3.util.Combinations.LexicographicComparator
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator<int[]>
- Enclosing class:
- Combinations
private static class Combinations.LexicographicComparator extends java.lang.Object implements java.util.Comparator<int[]>, java.io.Serializable
Defines the lexicographic ordering of combinations, using thelexNorm(int[])
method.
-
-
Field Summary
Fields Modifier and Type Field Description private int
k
Number of elements in each combination.private int
n
Size of the set from which combinations are drawn.private static long
serialVersionUID
Serializable version identifier.
-
Constructor Summary
Constructors Constructor Description LexicographicComparator(int n, int k)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(int[] c1, int[] c2)
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.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serializable version identifier.- See Also:
- Constant Field Values
-
n
private final int n
Size of the set from which combinations are drawn.
-
k
private final int k
Number of elements in each combination.
-
-
Method Detail
-
compare
public int compare(int[] c1, int[] c2)
- Specified by:
compare
in interfacejava.util.Comparator<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 ifc
is{3, 2, 1}
, andn
is 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
).
-
-