Class Sort

java.lang.Object
io.keikai.doc.collab.lib0.Sort

public class Sort extends Object
Efficient sort implementations. Note: These sort implementations were created to compare different sorting algorithms in JavaScript. Don't use them if you don't know what you are doing. Native Array.sort is almost always a better choice.
  • Method Details

    • insertionSort

      public static <T> void insertionSort(T[] arr, Comparator<T> compare)
      Public insertion sort implementation for sorting the entire array.
      Type Parameters:
      T - The type of elements in the array.
      Parameters:
      arr - The array to sort.
      compare - A comparator to compare the elements.
    • quicksort

      public static <T> void quicksort(T[] arr, Comparator<T> compare)
      This algorithm beats Array.prototype.sort in Chrome only with arrays with 10 million entries. In most cases [].sort will do just fine. Make sure to performance test your use-case before you integrate this algorithm. Note that Chrome's sort is now a stable algorithm (Timsort). Quicksort is not stable.
      Type Parameters:
      T - The type of elements in the array.
      Parameters:
      arr - The array to sort.
      compare - A comparator to compare the elements.