The OpenD Programming Language

sort

Sorts ndslice, array, or series.

  1. Slice!(Iterator, N, kind) sort(Slice!(Iterator, N, kind) slice)
    template sort(alias less = "a < b")
    static if(__traits(isSame, naryFun!less, less))
    Slice!(Iterator, N, kind)
    sort
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
  2. T[] sort(T[] ar)
  3. Series!(IndexIterator, Iterator, N, kind) sort(Series!(IndexIterator, Iterator, N, kind) series)
  4. Series!(IndexIterator, Iterator, N, kind) sort(Series!(IndexIterator, Iterator, N, kind) series, Slice!SortIndexIterator indexBuffer, Slice!DataIterator dataBuffer)

Members

Functions

sort
Slice!(Iterator, N, kind) sort(Slice!(Iterator, N, kind) slice)

Sort n-dimensional slice.

sort
T[] sort(T[] ar)

Sort for arrays

sort
Series!(IndexIterator, Iterator, N, kind) sort(Series!(IndexIterator, Iterator, N, kind) series)

Sort for one-dimensional Series.

sort
Series!(IndexIterator, Iterator, N, kind) sort(Series!(IndexIterator, Iterator, N, kind) series, Slice!SortIndexIterator indexBuffer, Slice!DataIterator dataBuffer)

Sort for n-dimensional Series.

Examples

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

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

auto data = arr[].sliced(arr.length);
data.sort();
assert(data.pairwise!"a <= b".all);

one-dimensional series

import mir.series;

auto index = [4, 2, 1, 3, 0].sliced;
auto data = [5.6, 3.4, 2.1, 7.8, 0.1].sliced;
auto series = index.series(data);
series.sort;
assert(series.index == [0, 1, 2, 3, 4]);
assert(series.data == [0.1, 2.1, 3.4, 7.8, 5.6]);
/// initial index and data are the same
assert(index.iterator is series.index.iterator);
assert(data.iterator is series.data.iterator);

foreach(obs; series)
{
    static assert(is(typeof(obs) == Observation!(int, double)));
}

two-dimensional series

import mir.series;
import mir.ndslice.allocation: uninitSlice;

auto index = [4, 2, 3, 1].sliced;
auto data =
    [2.1, 3.4, 
     5.6, 7.8,
     3.9, 9.0,
     4.0, 2.0].sliced(4, 2);
auto series = index.series(data);

series.sort(
    uninitSlice!size_t(series.length), // index buffer
    uninitSlice!double(series.length), // data buffer
    );

assert(series.index == [1, 2, 3, 4]);
assert(series.data ==
    [[4.0, 2.0],
     [5.6, 7.8],
     [3.9, 9.0],
     [2.1, 3.4]]);
/// initial index and data are the same
assert(index.iterator is series.index.iterator);
assert(data.iterator is series.data.iterator);

See Also

Meta