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 Details

    • serialVersionUID

      private static final long serialVersionUID
      Serializable version identifier.
      See Also:
    • 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.
  • 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:
      compare in interface Comparator<int[]>
      Throws:
      DimensionMismatchException - if the array lengths are not equal to k.
      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 base n) in the input array in reverse order. For example if c is {3, 2, 1}, and n 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).