Class DoubleArraySorter


  • public class DoubleArraySorter
    extends Object
    This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
    All methods in this class throw a NullPointerException if the specified array reference is null, except where noted.
    The documentation for the methods contained in this class includes briefs description of the implementations. Such descriptions should be regarded as implementation notes, rather than parts of the specification. Implementors should feel free to substitute other algorithms, so long as the specification itself is adhered to. (For example, the algorithm used by sort(Object[]) does not have to be a mergesort, but it does have to be stable.)
    This class is a member of the Java Collections Framework.
    Since:
    1.2
    Version:
    1.71, 04/21/06
    Author:
    Josh Bloch, Neal Gafter, John Rose
    • Method Detail

      • sort

        public static void sort​(double[] first,
                                double[] second)
        Sorts the specified arrays of doubles into ascending numerical order. Only the first array is used to sort. The second array is sorted using the same order as the first one
        The < relation does not provide a total order on all floating-point values; although they are distinct numbers -0.0 == 0.0 is true and a NaN value compares neither less than, greater than, nor equal to any floating-point value, even itself. To allow the sort to proceed, instead of using the < relation to determine ascending numerical order, this method uses the total order imposed by Double.compareTo(java.lang.Double). This ordering differs from the < relation in that -0.0 is treated as less than 0.0 and NaN is considered greater than any other floating-point value. For the purposes of sorting, all NaN values are considered equivalent and equal.
        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.
        Parameters:
        first - the array to be sorted
        second - second array to be sorted
      • sort

        public static void sort​(double[] first,
                                double[] second,
                                int fromIndex,
                                int toIndex)
        Sorts the specified range of the specified arrays of doubles into ascending numerical order. Sorts the specified arrays of doubles into ascending numerical order. Only the first array is used to sort. The second array is sorted using the same order as the first one The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)
        The < relation does not provide a total order on all floating-point values; although they are distinct numbers -0.0 == 0.0 is true and a NaN value compares neither less than, greater than, nor equal to any floating-point value, even itself. To allow the sort to proceed, instead of using the < relation to determine ascending numerical order, this method uses the total order imposed by Double.compareTo(java.lang.Double). This ordering differs from the < relation in that -0.0 is treated as less than 0.0 and NaN is considered greater than any other floating-point value. For the purposes of sorting, all NaN values are considered equivalent and equal.
        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.
        Parameters:
        first - the array to be sorted
        second - second array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        Throws:
        IllegalArgumentException - if fromIndex > toIndex
        ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > a.length