Class LongComparators

java.lang.Object
com.github.tommyettinger.ds.support.sort.LongComparators

public final class LongComparators extends Object
A class providing static methods and objects that do useful things with comparators.
  • Field Details

    • NATURAL_COMPARATOR

      public static final LongComparator NATURAL_COMPARATOR
    • OPPOSITE_COMPARATOR

      public static final LongComparator OPPOSITE_COMPARATOR
    • UNSIGNED_COMPARATOR

      public static final LongComparator UNSIGNED_COMPARATOR
    • UNSIGNED_OPPOSITE_COMPARATOR

      public static final LongComparator UNSIGNED_OPPOSITE_COMPARATOR
  • Method Details

    • oppositeComparator

      public static LongComparator oppositeComparator(LongComparator c)
      Returns a comparator representing the opposite order of the given comparator.
      Parameters:
      c - a comparator.
      Returns:
      a comparator representing the opposite order of c.
    • asLongComparator

      public static LongComparator asLongComparator(Comparator<? super Long> c)
      Returns a type-specific comparator that is equivalent to the given comparator.
      Parameters:
      c - a comparator, or null.
      Returns:
      a type-specific comparator representing the order of c.
    • sort

      public static void sort(long[] items, LongComparator c)
      Sorts all of items by simply calling sort(long[], int, int, LongComparator), setting from and to so the whole array is sorted.
      Parameters:
      items - the long array to be sorted
      c - a LongComparator to alter the sort order; if null, the natural order will be used
    • sort

      public static void sort(long[] items, int from, int to, LongComparator c)
      Sorts the specified range of elements according to the order induced by the specified comparator using mergesort.

      This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. The sorting algorithm is an in-place mergesort that is significantly slower than a standard mergesort, as its running time is O(n (log n)2), but it does not allocate additional memory; as a result, it can be used as a generic sorting algorithm.

      If and only if c is null, this will delegate to Arrays.sort(long[], int, int), which does not have the same guarantees regarding allocation.

      Parameters:
      items - the long array to be sorted
      from - the index of the first element (inclusive) to be sorted.
      to - the index of the last element (exclusive) to be sorted.
      c - a LongComparator to alter the sort order; if null, the natural order will be used