Expand description
Parallel merge sort.
This implementation is copied verbatim from std::slice::sort
and then parallelized.
The only difference from the original is that the sequential mergesort
returns
MergesortResult
and leaves descending arrays intact.
Structsยง
- CopyOnDrop ๐When dropped, copies from
src
intodest
a sequence of lengthlen
. - Run ๐A sorted run that starts at index
start
and is of lengthlen
.
Enumsยง
- MergesortResult ๐The result of merge sort.
Functionsยง
- collapse ๐Examines the stack of runs and identifies the next pair of runs to merge. More specifically, if
Some(r)
is returned, that meansruns[r]
andruns[r + 1]
must be merged next. If the algorithm should continue building a new run instead,None
is returned. - decrement_and_get ๐ โ
- get_and_increment ๐ โ
- insert_head ๐Inserts
v[0]
into pre-sorted sequencev[1..]
so that wholev[..]
becomes sorted. - merge ๐ โMerges non-decreasing runs
v[..mid]
andv[mid..]
usingbuf
as temporary storage, and stores the result intov[..]
. - mergesort ๐ โSorts a slice using merge sort, unless it is already in descending order.
- par_merge ๐ โMerges slices
left
andright
in parallel and stores the result intodest
. - par_mergesort ๐Sorts
v
using merge sort in parallel. - recurse ๐ โRecursively merges pre-sorted chunks inside
v
. - split_for_merge ๐Splits two sorted slices so that they can be merged in parallel.