find

Finds a backward index such that series.index[$ - backward_index] == key.

@optmath
size_t
find
(
IndexIterator
Iterator
size_t N
SliceKind kind
Index
)
(
Series!(IndexIterator, Iterator, N, kind) series
,
auto ref scope const Index key
)

Parameters

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

series

key Index

index key to find in the series

Return Value

Type: size_t

0 if the series does not contain the key and appropriate backward index otherwise.

Examples

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

if (auto bi = series.find(3))
{
    assert(series.data[$ - bi] == 5.6);
}
else
{
    assert(0);
}

assert(series.find(0) == 0);

Meta