tarantool / tarantool/doc

A new `index:offset_of` method introduced

Open
#4,504 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.3 index reference
Dominant language
CSS
Stars
15
Forks
49
Avg merge
1d 13h
Merged PRs (30d)
3

Description

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 https://github.com/tarantool/tarantool/commit/21e428eaf8335b747e2f6072e3798a3edaef6aac.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the new reference page under reference/reference_lua/box_index/ and review whether platform/ddl_dml/using_indexes/ also needs coverage. Document index:offset_of for every iterator behavior and the matching and non-matching examples shown in the issue; it is done when the method's return position and direction rules are clear in the relevant Tarantool documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.