This is a submodule of .

Note:

The combination of with lambda

"a <= b"
(
"a < b"
) and can be used to check if an ndslice is sorted (strictly monotonic). can be used to make an index. and can be used to create Schwartzian transform. See also the examples in the module.

License

.

Copyright

Andrei Alexandrescu 2008-2016, Ilya Yaroshenko 2016-,

Authors

Andrei Alexandrescu (Phobos), Ilya Yaroshenko (API, rework, Mir adoptation)

See Also:

isSorted
and
isStrictlyMonotonic

Example

Check if ndslice is sorted, or strictly monotonic.

import mir.algorithm.iteration: all;
import mir.ndslice.slice: sliced;
import mir.ndslice.sorting: sort;
import mir.ndslice.topology: pairwise;

auto arr = [1, 1, 2].sliced;

assert(arr.pairwise!"a <= b".all);
assert(!arr.pairwise!"a < b".all);

arr = [4, 3, 2, 1].sliced;

assert(!arr.pairwise!"a <= b".all);
assert(!arr.pairwise!"a < b".all);

sort(arr);

assert(arr.pairwise!"a <= b".all);
assert(arr.pairwise!"a < b".all);

Example

Create index

import mir.algorithm.iteration: all;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.ndslice.sorting: sort;
import mir.ndslice.topology: iota, pairwise;

auto arr = [4, 2, 3, 1].sliced;

auto index = arr.length.iota.slice;
index.sort!((a, b) => arr[a] < arr[b]);

assert(arr[index].pairwise!"a <= b".all);

Example

Schwartzian transform

import mir.algorithm.iteration: all;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.ndslice.sorting: sort;
import mir.ndslice.topology: zip, map, pairwise;

alias transform = (a) => (a - 3) ^^ 2;

auto arr = [4, 2, 3, 1].sliced;

arr.map!transform.slice.zip(arr).sort!((l, r) => l.a < r.a);

assert(arr.map!transform.pairwise!"a <= b".all);

Functions

quickSortImpl@trusted
makeIndexReturns:

Index slice/array.

makeIndex

Templates

sort
transitionIndex