box: introduce next and previous prefix iterators
Implement 'np' (next prefix) and 'pp' (previous prefix) iterators. They work only in memtx tree and in a nutshell searches for strings with greater ('np') or less ('pp') prefix of size as in given key, comparing with given key. Closes #9994 @TarantoolBot document Title: 'np' and 'pp' (next/previous prefix) iterators Now there are two more iterators available: 'np' (next prefix) and 'pp' (previous prefix). They work only in memtx tree. Also, if the last part of key is not a string, they degrade to 'gt' and 'lt' iterators. These iterators introduce special comparison of the last part of key (if it is a string). In terms of lua, if s is the search part, and t is the corresponding tuple part, 'np' iterator searches for the first tuple with string.sub(t, 1, #s) > s, while 'pp' searches for the last tuple with string.sub(t, 1, #s) < s. Comparison of all other parts of the key remains normal. As usual, these iterators are available both in select and pairs, in index and space methods. Similar to all other tree iterators, they change only initial search of selection. Once the first tuple found, the rest are selected sequentially in direct (for 'np') or reverse (for 'pp') order of the index. For example: ``` tarantool> s:select{} --- - - ['a'] - ['aa'] - ['ab'] - ['b'] - ['ba'] - ['bb'] - ['c'] - ['ca'] - ['cb'] ... tarantool> s:select({'b'}, {iterator = 'np'}) --- - - ['c'] - ['ca'] - ['cb'] ... tarantool> s:select({'b'}, {iterator = 'pp'}) --- - - ['ab'] - ['aa'] - ['a'] ... ```
Showing
- changelogs/unreleased/gh-9994-next-prefix-iterator.md 4 additions, 0 deletionschangelogs/unreleased/gh-9994-next-prefix-iterator.md
- src/box/iterator_type.c 2 additions, 0 deletionssrc/box/iterator_type.c
- src/box/iterator_type.h 17 additions, 11 deletionssrc/box/iterator_type.h
- src/box/memtx_tree.cc 86 additions, 1 deletionsrc/box/memtx_tree.cc
- test/box-luatest/gh_9994_next_prefix_iterator_test.lua 405 additions, 0 deletionstest/box-luatest/gh_9994_next_prefix_iterator_test.lua
Loading
Please register or sign in to comment