TimSorter

abstract class TimSorter : Sorter

Sorter implementation based on the TimSort algorithm. It sorts small arrays with a binary sort.

This algorithm is stable. It's especially good at sorting partially-sorted arrays.

NOTE:There are a few differences with the original implementation:

  • The extra amount of memory to perform merges is configurable. This allows small merges to be very fast while large merges will be performed in-place (slightly slower). You can make sure that the fast merge routine will always be used by having maxTempSlots equal to half of the length of the slice of data to sort.

  • Only the fast merge routine can gallop (the one that doesn't run in-place) and it only gallops on the longest slice.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
var minRun: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var to: Int

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 override fun doRotate(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
Link copied to clipboard
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 lowerSaved(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun lowerSaved3(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun merge(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
fun mergeAt(n: Int)
Link copied to clipboard
fun mergeHi(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
fun mergeInPlace(from: Int, mid: Int, to: Int)
Link copied to clipboard
fun mergeLo(lo: Int, mid: Int, hi: Int)
Link copied to clipboard
fun nextRun(): Int

Compute the length of the next run, make the run sorted and return its length.

Link copied to clipboard
fun pushRunLen(len: Int)
Link copied to clipboard
fun reset(from: 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 runBase(i: Int): Int
Link copied to clipboard
fun runEnd(i: Int): Int
Link copied to clipboard
fun runLen(i: Int): Int
Link copied to clipboard
fun setRunEnd(i: Int, runEnd: Int)
Link copied to clipboard
fun siftDown(i: Int, from: Int, to: Int)
Link copied to clipboard
open override 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
Link copied to clipboard
fun upperSaved(from: Int, to: Int, val: Int): Int
Link copied to clipboard
fun upperSaved3(from: Int, to: Int, val: Int): Int