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.
Function std.algorithm.sorting.topNCopy
Copies the top n
elements of the
input range source
into the
random-access range target
, where `n $D(
target.length). Elements of source
are not touched. If sorted
is true
, the target is sorted. Otherwise, the target
respects the heap property.
TRange topNCopy(alias less, SRange, TRange)
(
SRange source,
TRange target,
SortOutput sorted = No .sortOutput
)
if (isInputRange!SRange && isRandomAccessRange!TRange && hasLength!TRange && hasSlicing!TRange);
Parameters
Name | Description |
---|---|
less | The predicate to sort by. |
source | The source range. |
target | The target range. |
sorted | Whether to sort the elements copied into target . |
Returns
The slice of target
containing the copied elements.
Example
import std .typecons : Yes;
int[] a = [ 10, 16, 2, 3, 1, 5, 0 ];
int[] b = new int[3];
topNCopy(a, b, Yes .sortOutput);
writeln(b); // [0, 1, 2]
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.