Expand description
Parallel Slice sorting
This implementation is mostly copied from the core::slice::sort module, with minimal changes
to support stable Rust and parallel is_less (e.g. Fn rather than FnMut).
This module contains a sorting algorithm based on Orson Petersβ pattern-defeating quicksort, published at: https://github.com/orlp/pdqsort
Unstable sorting is compatible with core because it doesnβt allocate memory, unlike our stable sorting implementation.
In addition it also contains the core logic of the stable sort used by slice::sort based on
TimSort.
StructsΒ§
- Insertion
Hole π - Merge
Hole π - TimSort
Run π - Internal type used by merge_sort.
 
EnumsΒ§
- Merge
Sort πResult  - The result of merge sort.
 
FunctionsΒ§
- break_
patterns π - Scatters some elements around in an attempt to break patterns that might cause imbalanced partitions in quicksort.
 - choose_
pivot π - Chooses a pivot in 
vand returns the index andtrueif the slice is likely already sorted. - find_
streak π - Finds a streak of presorted elements starting at the beginning of the slice. Returns the first value that is not part of said streak, and a bool denoting whether the streak was reversed. Streaks can be increasing or decreasing.
 - heapsort π
 - Sorts 
vusing heapsort, which guarantees O(n * log(n)) worst-case. - insert_
head π β - Inserts 
v[0]into pre-sorted sequencev[1..]so that wholev[..]becomes sorted. - insert_
tail π β - Inserts 
v[v.len() - 1]into pre-sorted sequencev[..v.len() - 1]so that wholev[..]becomes sorted. - insertion_
sort_ πshift_ left  - Sort 
vassumingv[..offset]is already sorted. - insertion_
sort_ πshift_ right  - Sort 
vassumingv[offset..]is already sorted. - merge π β
 - Merges non-decreasing runs 
v[..mid]andv[mid..]usingbufas temporary storage, and stores the result intov[..]. - merge_
recurse π β - Recursively merges pre-sorted chunks inside 
v. - merge_
sort π β - This merge sort borrows some (but not all) ideas from TimSort, which used to be described in detail here. However Python has switched to a Powersort based implementation.
 - par_
merge π β - Merges slices 
leftandrightin parallel and stores the result intodest. - par_
mergesort π - Sorts 
vusing merge sort in parallel. - par_
quicksort π - Sorts 
vusing pattern-defeating quicksort in parallel. - partial_
insertion_ πsort  - Partially sorts a slice by shifting several out-of-order elements around.
 - partition π
 - Partitions 
vinto elements smaller thanv[pivot], followed by elements greater than or equal tov[pivot]. - partition_
equal π - Partitions 
vinto elements equal tov[pivot]followed by elements greater thanv[pivot]. - partition_
in_ πblocks  - Partitions 
vinto elements smaller thanpivot, followed by elements greater than or equal topivot. - provide_
sorted_ πbatch  - Takes a range as denoted by start and end, that is already sorted and extends it to the right if necessary with sorts optimized for smaller ranges such as insertion sort.
 - recurse π
 - Sorts 
vrecursively. - split_
for_ πmerge  - Splits two sorted slices so that they can be merged in parallel.