Sorter

abstract class Sorter

Base class for sorting algorithms implementations.

There are a number of subclasses to choose from that vary in performance and stability. We suggest that you pick the first from this ranked list that meets your requirements:

  1. MSBRadixSorter for strings (array of bytes/chars). Not a stable sort.

  2. StableMSBRadixSorter for strings (array of bytes/chars). Stable sort.

  3. IntroSorter. Not a stable sort.

  4. InPlaceMergeSorter. When the data to sort is typically small. Stable sort.

  5. TimSorter. Stable sort.

Inheritors

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun binarySort(from: Int, to: Int, i: Int = from + 1)

A binary sort implementation. This performs O(n*log(n)) comparisons and O(n^2) swaps. It is typically used by more sophisticated implementations as a fall-back when the number of items to sort has become less than {@value #BINARY_SORT_THRESHOLD}. This algorithm is stable.

Link copied to clipboard
fun checkRange(from: Int, to: Int)
Link copied to clipboard
open fun doRotate(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
fun heapify(from: Int, to: Int)
Link copied to clipboard
fun heapSort(from: Int, to: Int)

Use heap sort to sort items between from inclusive and to exclusive. This runs in O(n*log(n)) and is used as a fall-back by IntroSorter. This algorithm is NOT stable.

Link copied to clipboard
fun insertionSort(from: Int, to: Int)

Sorts between from (inclusive) and to (exclusive) with insertion sort. Runs in O(n^2). It is typically used by more sophisticated implementations as a fall-back when the number of items to sort becomes less than {@value #INSERTION_SORT_THRESHOLD}. This algorithm is stable.

Link copied to clipboard
fun lower(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun lower2(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun mergeInPlace(from: Int, mid: Int, to: Int)
Link copied to clipboard
fun reverse(from: Int, to: Int)
Link copied to clipboard
fun rotate(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
fun siftDown(i: Int, from: Int, to: Int)
Link copied to clipboard
abstract fun sort(from: Int, to: Int)

Sort the slice which starts at from (inclusive) and ends at to (exclusive).

Link copied to clipboard
fun upper(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun upper2(from: Int, to: Int, val: Int): Int