The OpenD Programming Language

assumeSortedEqualIndex

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

Members

Functions

assumeSortedEqualIndex
sizediff_t assumeSortedEqualIndex(Slice!(Iterator, 1, kind) slice, V v)
sizediff_t assumeSortedEqualIndex(T[] ar, V v)

Parameters

test

strict ordering symmetric predicate.

For non-symmetric predicates please use a structure with two opCalls or an alias of two global functions, that correponds to (array[i], value) and (value, array[i]) cases.

Return Value

the smallest index of a sorted array such that the index corresponds to the arrays element at the index according to the predicate and -1 if the array doesn't contain corresponding element.

Examples

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

assert(a.assumeSortedEqualIndex(2) == 2);
assert(a.assumeSortedEqualIndex(5) == -1);

// <= non strict predicates doesn't work
assert(a.assumeSortedEqualIndex!"a <= b"(2) == -1);

See Also

Meta