Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Appended ¶
Appended sort a slice in assumption that the beginning of the slice is already sorted, and only tailLength new unsorted elements are added to the end of the slice. The function contains an optimization for a case where tailLength is low and it is possible to resort the slice faster than just through a full resorting.
For example if there is a slice of length 65536 with only 512 unsorted elements in the end, then `Appended` on my laptop works 7 times faster than just using `Slice` on the whole slice.
The algorithm is good if the unsorted right part of the array is much smaller than the sorted left part (see `docs/force_appended_benchmark.txt`), but otherwise it is worse than a simple quick sort. So it fallbacks to quicksort if the unsorted part is too big.
Roughly:
T: O(k*ln(n) + n + k^2) -- thus if `k` is too high then: O(k^2)
S: O(1) [if without `s`]
func AppendedWithBuf ¶
AppendedWithBuf is the same as Appended but: * Much faster. * Requires a buffer.
The buffer length should be exactly the same as the length of the unsorted tail.
For example if there is a slice of length 65536 with only 512 unsorted elements in the end, then `Appended` on my laptop works ~30 times faster than just using `Slice` on the whole slice.
T: O(k*ln(n) + n)
S: O(k) [if without `s`]