Function std.range.assumeSorted
Assumes
is sorted by predicate r
pred
and returns the
corresponding
having SortedRange
!(pred, R)
as support. To
keep the checking costs low, the cost is Ο(r
1
) in release mode
(no checks for sortedness are performed). In debug mode, a few random
elements of
are checked for sortedness. The size of the sample
is proportional Ο(r
log(r.length)
). That way, checking has no
effect on the complexity of subsequent operations specific to sorted
ranges (such as binary search). The probability of an arbitrary
unsorted range failing the test is very high (however, an
almost-sorted range is likely to pass it). To check for sortedness at
cost Ο(n
), use std.algorithm.sorting.isSorted
.
Prototype
auto assumeSorted(alias pred, R)( R r ) if (isInputRange!(Unqual!R));
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.