The OpenD Programming Language

makeIndex

  1. Slice!(I*) makeIndex(Slice!(Iterator, 1, kind) r)
  2. I[] makeIndex(T[] r)
    I[]
    makeIndex
    (
    I = size_t
    alias less = "a < b"
    T
    )
    (
    scope T[] r
    )

Examples

import mir.algorithm.iteration: all;
import mir.ndslice.topology: indexed, pairwise;

immutable arr = [ 2, 3, 1, 5, 0 ];
auto index = arr.makeIndex;

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

Sort based on index created from a separate array

import mir.algorithm.iteration: equal;
import mir.ndslice.topology: indexed;

immutable arr0 = [ 2, 3, 1, 5,  0 ];
immutable arr1 = [ 1, 5, 4, 2, -1 ];

auto index = makeIndex(arr0);
assert(index.equal([4, 2, 0, 1, 3]));
auto view = arr1.indexed(index);
assert(view.equal([-1, 4, 1, 5, 2]));

Meta