Open
Description
Product: Tarantool
Since: 3.3.0
Root document:
- new page in https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_index/
- (possibly) https://www.tarantool.io/en/doc/latest/platform/ddl_dml/using_indexes/
SME: @ mkostoevr
Details
The method returns 0-based offset in the index of a first tuple
matching the provided key and iterator. The position is counted from
the beginning or end of the space depending on the iterator direction,
for example:
-- index: {{1}, {3}}
index:offset_of({3}, {iterator = 'eq'}) -- returns 1: [1, <3>]
index:offset_of({3}, {iterator = 'req'}) -- returns 0: [<3>, 1]
In case there's no tuple matching the key and iterator in the index the
function returns the position a matching tuple would be placed at if
existed, for example:
-- index: {{1}, {3}}
index:offset_of({2}, {iterator = 'eq'}) -- 1: [1, <2>, 3]
index:offset_of({4}, {iterator = 'req'}) -- 0: [<4>, 3, 1]
This works with any iterator:
-- index: {{1}, {3}}
index:offset_of({0}, {iterator = 'ge'}) -- 0: [<1>, 3]
index:offset_of({1}, {iterator = 'lt'}) -- 2: [3, 1, <...>]
-- index: {{'b'}, {'bb'}, {'bc'}, {'c'}, {'cc'}}
index:offset_of({'b'}, {iterator = 'np'}) -- 3: [b, bb, bc, <c>, cc]
index:offset_of({'cc'}, {iterator = 'pp'}) -- 1: [cc, <c>, bc, bb, b]
Requested by @mkostoevr in tarantool/tarantool@21e428e.