The OpenD Programming Language

partialSort

Reorders the random-access range r such that the range r[0 .. mid] is the same as if the entire r were sorted, and leaves the range r[mid .. r.length] in no particular order.

Performs O(r.length * log(mid)) evaluations of pred. The implementation simply calls topN!(less, ss)(r, n) and then sort!(less, ss)(r[0 .. n]).

  1. void partialSort(Range r, size_t n)
    void
    partialSort
    (
    alias less = "a < b"
    Range
    )
    (
    Range r
    ,
    size_t n
    )
    if (
    hasLength!(Range)
    &&
    hasSlicing!(Range)
    )
  2. void partialSort(Range1 r1, Range2 r2)

Parameters

less

The predicate to sort by.

ss

The swapping strategy to use.

r Range

The random-access range to reorder.

n size_t

The length of the initial segment of r to sort.

Examples

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

Meta