Class Lehmer

java.lang.Object
org.aksw.commons.util.math.Lehmer

public class Lehmer extends Object
Class for computing the lehmer code and value for a given set of items w.r.t. a comparator. The lehmer code is a basis for numbering permutations. The (decimal) value of a lehmer code for n items ranges from 0 to n!. The value is 0 for a sorted sequence of items and n! for a reverse-sorted one.
  • Constructor Details

    • Lehmer

      public Lehmer()
  • Method Details

    • lehmerValue

      public static <T> BigInteger lehmerValue(Collection<T> items, Comparator<T> comparator)
    • lehmerCode

      public static <T> int[] lehmerCode(Collection<T> items, Comparator<T> comparator)
      For a given collection of unique items with a defined total ordering (via comparator) compute the natural number that correspends to n-th permutation w.r.t. the lehmer code. This implementation adds the provided items into a LinkedHashSet - so only their first occurrence matters.
      Type Parameters:
      T -
      Parameters:
      items -
      comparator -
      Returns:
    • valueOfLehmerCode

      public static BigInteger valueOfLehmerCode(int[] lehmer)