View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

std.algorithm.sorting.partialSort - multiple declarations

Function partialSort

Reorders the random-access range r such that the range `r[$D( .. mid]) is the same as if the entire r were sorted, and leaves the range r[mid .. r.length] in no particular order. Performs Ο(r.length * log(mid)) evaluations of pred. The implementation simply calls topN!(less, ss)(r, n) and then sort!(less, ss)(r[0 .. n]).

void partialSort(alias less, SwapStrategy ss = SwapStrategy.unstable, Range) (
  Range r,
  size_t n
)
if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range);

Parameters

NameDescription
less The predicate to sort by.
ss The swapping strategy to use.
r The random-access range to reorder.
n The length of the initial segment of r to sort.

Example

int[] a = [ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ];
partialSort(a, 5);
writeln(a[0 .. 5]); // [0, 1, 2, 3, 4]

Function partialSort

Stores the smallest elements of the two ranges in the left-hand range in sorted order.

void partialSort(alias less, SwapStrategy ss = SwapStrategy.unstable, Range1, Range2) (
  Range1 r1,
  Range2 r2
)
if (isRandomAccessRange!Range1 && hasLength!Range1 && isInputRange!Range2 && is(ElementType!Range1 == ElementType!Range2) && hasLvalueElements!Range1 && hasLvalueElements!Range2);

Parameters

NameDescription
less The predicate to sort by.
ss The swapping strategy to use.
r1 The first range.
r2 The second range.

Example

int[] a = [5, 7, 2, 6, 7];
int[] b = [2, 1, 5, 6, 7, 3, 0];

partialSort(a, b);
writeln(a); // [0, 1, 2, 2, 3]

Authors

Andrei Alexandrescu

License

Boost License 1.0.