Class 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 a lexicographic ordering of the combinations. The comparison is based on the value (in base 10) represented by the digit (interpreted in base n) in the input array, in reverse order.
    • 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.
    • 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 base n) in the input array in reverse order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • 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.
    • Constructor Detail

      • 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 Detail

      • compare

        public int compare​(int[] c1,
                           int[] c2)
        Specified by:
        compare in interface java.util.Comparator<int[]>
        Throws:
        java.lang.IllegalArgumentException - if the array lengths are not equal to k.
        java.lang.IllegalArgumentException - 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:
        java.lang.IllegalArgumentException - if an element of the array is not within the interval [0, n).