Skip to content

A new index:offset_of method introduced #4504

Open
@TarantoolBot

Description

@TarantoolBot

Product: Tarantool
Since: 3.3.0
Root document:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.3indexRelated to Tarantool indexesreference[location] Tarantool manual, Reference part

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions