Class QuickSort

java.lang.Object
com.carrotsearch.hppc.sorting.QuickSort

public final class QuickSort extends Object
In-place Quick sort with 3-way partitioning and ending with Insertion sort.

The sorting is not stable. Performance is O(n.log(n)) and memory is O(1) (although recursion memory is O(log(n))).

  • Method Details

    • sort

      public static void sort(int[] array, IntBinaryOperator comparator)
      See Also:
    • sort

      public static void sort(int[] array, int fromIndex, int toIndex, IntBinaryOperator comparator)
      See Also:
    • sort

      public static void sort(int fromIndex, int toIndex, IntBinaryOperator comparator, IntBinaryOperator swapper)
      Performs a recursive in-place Quick sort. The sorting is not stable.
      Parameters:
      fromIndex - Index where to start sorting in the array, inclusive.
      toIndex - Index where to stop sorting in the array, exclusive.
      comparator - Compares elements based on their indices. Given indices i and j in the provided array, this comparator returns respectively -1/0/1 if the element at index i is respectively less/equal/greater than the element at index j.
      swapper - Swaps the elements in the array at the given indices. For example, a custom swapper may allow sorting two arrays simultaneously.