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.topNCopy
Copies the top n
elements of the input range
into the
random-access range source
, where target
n =
target.length
. Elements of
are not touched. If source
is sorted
true
, the target
is sorted
. Otherwise, the target
respects the heap property.
Prototype
TRange topNCopy(alias less, SRange, TRange)( SRange source, TRange target, SortOutput sorted = SortOutput.no ) 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 . |
Returns
The slice of
containing the copied elements.
target
Example
int[] a = [ 10, 16, 2, 3, 1, 5, 0 ]; int[] b = new int[3]; topNCopy(a, b, SortOutput.yes); assert(b == [ 0, 1, 2 ]);