Class Combinations.LexicographicComparator
- java.lang.Object
-
- org.apache.commons.numbers.combinatorics.Combinations.LexicographicComparator
-
- All Implemented Interfaces:
java.io.Serializable,java.util.Comparator<int[]>
- Enclosing class:
- Combinations
public static class Combinations.LexicographicComparator extends java.lang.Object implements java.util.Comparator<int[]>, java.io.SerializableDefines a lexicographic ordering of the combinations. The comparison is based on 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.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LexicographicComparator(int n, int k)
-
-
-
Method Detail
-
getN
public int getN()
Gets the size of the set from which combinations are drawn.- Returns:
- the size of the universe.
-
getK
public int getK()
Gets the number of elements in each combination.- Returns:
- the size of the subsets.
-
compare
public int compare(int[] c1, int[] c2)- Specified by:
comparein interfacejava.util.Comparator<int[]>- Throws:
java.lang.IllegalArgumentException- if the array lengths are not equal tok.java.lang.IllegalArgumentException- if an element of the array is not within the interval [0,n).
-
-