The OpenD Programming Language

transitionIndex

Computes transition index using binary search. It is low-level API for lower and upper bounds of a sorted array.

  1. size_t transitionIndex(Slice!(Iterator, 1, kind) slice, V v)
    template transitionIndex(alias test = "a < b")
    static if(__traits(isSame, naryFun!test, test))
    size_t
    transitionIndex
    (
    Iterator
    SliceKind kind
    V
    )
    (
    auto ref Slice!(Iterator, 1, kind) slice
    ,
    auto ref scope const V v
    )
  2. size_t transitionIndex(T[] ar, V v)

Members

Functions

transitionIndex
size_t transitionIndex(Slice!(Iterator, 1, kind) slice, V v)
size_t transitionIndex(T[] ar, V v)

Parameters

test

ordering predicate for ((array[i], value)) pairs.

Examples

// sorted: a < b
auto a = [0, 1, 2, 3, 4, 6];

auto i = a.transitionIndex(2);
assert(i == 2);
auto lowerBound = a[0 .. i];

auto j = a.transitionIndex!"a <= b"(2);
assert(j == 3);
auto upperBound = a[j .. $];

assert(a.transitionIndex(a[$ - 1]) == a.length - 1);
assert(a.transitionIndex!"a <= b"(a[$ - 1]) == a.length);

See Also

Meta