View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.sorting.partialSort
Reorders the random-access range such that the range r is the same as if the entire r[0
.. mid] were sorted, and leaves
the range r in no particular order. Performs
Ο(r[mid .. r.length]r.length * log(mid)) evaluations of pred. The
implementation simply calls and then topN!(less, ss)(r, n).
sort!(less, ss)(r[0 .. n])
Prototype
void partialSort(alias less, std.algorithm.mutation.SwapStrategy ss, Range)( Range r, size_t n ) if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range);
Example
int[] a = [ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ]; partialSort(a, 5); assert(a[0 .. 5] == [ 0, 1, 2, 3, 4 ]);