Report a bug
If you spot a problem with this page, click here to create a Github 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 a local clone.

mir.ndslice.sorting

This is a submodule of mir.ndslice.
Authors:
Ilya Yaroshenko, Andrei Alexandrescu
template isSorted(alias less = "a < b")

template isStrictlyMonotonic(alias less = "a < b")
Checks whether a slice is sorted according to the comparison operation less. Performs Ο(ndslice.elementsCount) evaluations of less. Unlike isSorted, isStrictlyMonotonic">isStrictlyMonotonic does not allow for equal values, i.e. values for which both less(a, b) and less(b, a) are false. With either function, the predicate must be a strict ordering just like with isSorted. For example, using "a <= b" instead of "a < b" is incorrect and will cause failed assertions.
Parameters:
less Predicate the range should be sorted by.
bool isSorted(SliceKind kind, size_t[] packs, Iterator)(Slice!(kind, packs, Iterator) slice)
if (packs.length == 1);
slice = A slice to check for sortedness.
Returns:
true if the range is sorted, false otherwise. isSorted allows duplicates, isStrictlyMonotonic not.
template sort(alias less = "a < b")
Examples:
import mir.ndslice.slice;

int[10] arr = [7,1,3,2,9,0,5,4,8,6];

auto data = arr[].ptr.sliced(arr.length);
data.sort();
assert(data.isSorted);
Slice!(kind, packs, Iterator) sort(SliceKind kind, size_t[] packs, Iterator)(Slice!(kind, packs, Iterator) slice)
if (packs.length == 1);