Class Sorting


  • public final class Sorting
    extends java.lang.Object
    Utility methods for sorting.
    Author:
    Michael Knopf
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int[] sort​(double[] src, Order order)
      Indirect stable sort of double values using the given order.
      static int[] sort​(int length, java.util.Comparator<java.lang.Integer> comparator, Order order)
      Sorts the indices [0, 1, ..., length-1] with respect to the given comparator and order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • sort

        public static int[] sort​(int length,
                                 java.util.Comparator<java.lang.Integer> comparator,
                                 Order order)
        Sorts the indices [0, 1, ..., length-1] with respect to the given comparator and order.
        Parameters:
        length - the length of the index array
        comparator - the comparator to use
        order - the sorting order
        Returns:
        the sorted indices
      • sort

        public static int[] sort​(double[] src,
                                 Order order)
        Indirect stable sort of double values using the given order. This method does not modify the given source array. Instead, it computes and returns an index mapping that if applied to the input results in a sorted sequence. Following Arrays.sort(double[]), this method uses the total order imposed by the method Double.compareTo(java.lang.Double).
        Parameters:
        src - the source array (remains unchanged))
        order - the sorting order
        Returns:
        the index mapping resulting in a sorted sequence
        Throws:
        java.lang.NullPointerException - if the source array or the order is null