## org.apache.mahout.math
Class Sorting

    java.lang.Object
      org.apache.mahout.math.Sorting

    public final class Sorting

extends Object

Method Summary
`static void` `mergeSort(byte[] array, int start, int end)` Perform a merge sort on a range of a byte array, using numerical order.
`static void` `mergeSort(byte[] array, int start, int end, ByteComparator comp)` Perform a merge sort on a range of a byte array using a specified ordering.
`static void` `mergeSort(char[] array, int start, int end)` Perform a merge sort on a range of a char array, using numerical order.
`static void` `mergeSort(char[] array, int start, int end, CharComparator comp)` Perform a merge sort on a range of a char array using a specified ordering.
`static void` `mergeSort(double[] array, int start, int end)` Perform a merge sort on a range of a double array using a Double.compare as an ordering.
`static void` `mergeSort(double[] array, int start, int end, DoubleComparator comp)` Perform a merge sort on a range of a double array using a specified ordering.
`static void` `mergeSort(float[] array, int start, int end)` Perform a merge sort on a range of a float array using Float.compare for an ordering.
`static void` `mergeSort(float[] array, int start, int end, FloatComparator comp)` Perform a merge sort on a range of a float array using a specified ordering.
`static void` `mergeSort(int[] array, int start, int end)`
`static void` `mergeSort(int[] array, int start, int end, IntComparator comp)` Perform a merge sort on a range of a int array using numerical order.
`static void` `mergeSort(int fromIndex, int toIndex, IntComparator c, Swapper swapper)` Sorts the specified range of elements according to the order induced by the specified comparator.
`static void` `mergeSort(long[] array, int start, int end)` Perform a merge sort on a range of a long array using numerical order.
`static void` `mergeSort(long[] array, int start, int end, LongComparator comp)` Perform a merge sort on a range of a long array using a specified ordering.
`static void` `mergeSort(short[] array, int start, int end)` Perform a merge sort on a range of a short array, using numerical order.
`static void` `mergeSort(short[] array, int start, int end, ShortComparator comp)`

`static

`<T extends Comparable<? super T>> void`

`

`mergeSort(T[] array, int start, int end)`
Perform a merge sort of the specific range of an array of objects that implement Comparable.

`static

`<T> void`

`

`mergeSort(T[] array, int start, int end, Comparator<T> comp)`
Perform a merge sort on the specified range of an array.

`static void` `quickSort(byte[] array, int start, int end, ByteComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(char[] array, int start, int end, CharComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(double[] array, int start, int end, DoubleComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(float[] array, int start, int end, FloatComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(int[] array, int start, int end, IntComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(int start, int end, IntComparator comp, Swapper swap)` Sorts some external data with QuickSort.
`static void` `quickSort(long[] array, int start, int end, LongComparator comp)` Sorts the specified range in the array in a specified order.
`static void` `quickSort(short[] array, int start, int end, ShortComparator comp)` Sorts the specified range in the array in ascending numerical order.

`static

`<T extends Comparable<? super T>> void`

`

`quickSort(T[] array, int start, int end)`
Sort the specified range of an array of object that implement the Comparable interface.

`static

`<T> void`

`

`quickSort(T[] array, int start, int end, Comparator<T> comp)`
Sorts the specified range in the array in a specified order.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### quickSort

    public static void quickSort(byte[] array,
                                 int start,
                                 int end,
                                 ByteComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `byte` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparison that determines the sort.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static void quickSort(int start,
                                 int end,
                                 IntComparator comp,
                                 Swapper swap)

  Sorts some external data with QuickSort.

  Parameters:
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparator.
    `swap` - an object that can exchange the positions of two items.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static void quickSort(char[] array,
                                 int start,
                                 int end,
                                 CharComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `char` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static void quickSort(double[] array,
                                 int start,
                                 int end,
                                 DoubleComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `double` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparison.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.
  See Also:
    `Double.compareTo(Double)`

### quickSort

    public static void quickSort(float[] array,
                                 int start,
                                 int end,
                                 FloatComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `float` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparator.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static void quickSort(int[] array,
                                 int start,
                                 int end,
                                 IntComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `int` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparator.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static void quickSort(long[] array,
                                 int start,
                                 int end,
                                 LongComparator comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the `long` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparator.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static <T> void quickSort(T[] array,
                                     int start,
                                     int end,
                                     Comparator<T> comp)

  Sorts the specified range in the array in a specified order.

  Parameters:
    `array` - the array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
    `comp` - the comparator.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### quickSort

    public static <T extends Comparable<? super T>> void quickSort(T[] array,
                                                                   int start,
                                                                   int end)

  Sort the specified range of an array of object that implement the Comparable interface.

  Type Parameters:
    `T` - The type of object.
  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### quickSort

    public static void quickSort(short[] array,
                                 int start,
                                 int end,
                                 ShortComparator comp)

  Sorts the specified range in the array in ascending numerical order.

  Parameters:
    `array` - the `short` array to be sorted.
    `start` - the start index to sort.
    `end` - the last + 1 index to sort.
  Throws:
    `IllegalArgumentException` - if `start > end`.
    `ArrayIndexOutOfBoundsException` - if `start < 0` or `end > array.length`.

### mergeSort

    public static <T> void mergeSort(T[] array,
                                     int start,
                                     int end,
                                     Comparator<T> comp)

  Perform a merge sort on the specified range of an array.

  Type Parameters:
    `T` - the type of object in the array.
  Parameters:
    `array` - the array.
    `start` - first index.
    `end` - last index (exclusive).
    `comp` - comparator object.

### mergeSort

    public static <T extends Comparable<? super T>> void mergeSort(T[] array,
                                                                   int start,
                                                                   int end)

  Perform a merge sort of the specific range of an array of objects that implement Comparable.

  Type Parameters:
    `T` - the type of the objects in the array.
  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(byte[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a byte array, using numerical order.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(byte[] array,
                                 int start,
                                 int end,
                                 ByteComparator comp)

  Perform a merge sort on a range of a byte array using a specified ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(char[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a char array, using numerical order.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(char[] array,
                                 int start,
                                 int end,
                                 CharComparator comp)

  Perform a merge sort on a range of a char array using a specified ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(short[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a short array, using numerical order.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(short[] array,
                                 int start,
                                 int end,
                                 ShortComparator comp)

### mergeSort

    public static void mergeSort(int[] array,
                                 int start,
                                 int end)

### mergeSort

    public static void mergeSort(int[] array,
                                 int start,
                                 int end,
                                 IntComparator comp)

  Perform a merge sort on a range of a int array using numerical order.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(long[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a long array using numerical order.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(long[] array,
                                 int start,
                                 int end,
                                 LongComparator comp)

  Perform a merge sort on a range of a long array using a specified ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(float[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a float array using Float.compare for an ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(float[] array,
                                 int start,
                                 int end,
                                 FloatComparator comp)

  Perform a merge sort on a range of a float array using a specified ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(double[] array,
                                 int start,
                                 int end)

  Perform a merge sort on a range of a double array using a Double.compare as an ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).

### mergeSort

    public static void mergeSort(double[] array,
                                 int start,
                                 int end,
                                 DoubleComparator comp)

  Perform a merge sort on a range of a double array using a specified ordering.

  Parameters:
    `array` - the array.
    `start` - the first index.
    `end` - the last index (exclusive).
    `comp` - the comparator object.

### mergeSort

    public static void mergeSort(int fromIndex,
                                 int toIndex,
                                 IntComparator c,
                                 Swapper swapper)

  Sorts the specified range of elements according to the order induced by the specified comparator. All elements in the range must be mutually comparable by the specified comparator (that is, `c.compare(a, b)` must not throw an exception for any indexes `a` and `b` in the range).

  This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

  The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

  Parameters:
    `fromIndex` - the index of the first element (inclusive) to be sorted.
    `toIndex` - the index of the last element (exclusive) to be sorted.
    `c` - the comparator to determine the order of the generic data.
    `swapper` - an object that knows how to swap the elements at any two indexes (a,b).
  See Also:
    `IntComparator`, `Swapper`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.