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ยง
- Copy
OnDrop ๐When dropped, copies fromsrc
intodest
a sequence of lengthlen
. - Run ๐A sorted run that starts at index
start
and is of lengthlen
.
Enumsยง
- Mergesort
Result ๐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 ๐Insertsv[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 slicesleft
andright
in parallel and stores the result intodest
. - par_
mergesort ๐Sortsv
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.