Skip to content
Snippets Groups Projects
Commit a2966b17 authored by Dmitry Simonenko's avatar Dmitry Simonenko
Browse files

index-iter-prev: lua index prev and select_reverse_range functions added

parent 153fef4f
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,15 @@ function box.select_range(sno, ino, limit, ...) ...@@ -40,6 +40,15 @@ function box.select_range(sno, ino, limit, ...)
return box.space[tonumber(sno)].index[tonumber(ino)]:select_range(tonumber(limit), ...) return box.space[tonumber(sno)].index[tonumber(ino)]:select_range(tonumber(limit), ...)
end end
--
-- Select a range of tuples in a given namespace via a given
-- index in reverse order. If key is NULL, starts from the end, otherwise
-- starts from the key.
--
function box.select_reverse_range(sno, ino, limit, ...)
return box.space[tonumber(sno)].index[tonumber(ino)]:select_reverse_range(tonumber(limit), ...)
end
-- --
-- delete can be done only by the primary key, whose -- delete can be done only by the primary key, whose
-- index is always 0. It doesn't accept compound keys -- index is always 0. It doesn't accept compound keys
...@@ -116,6 +125,16 @@ function box.on_reload_configuration() ...@@ -116,6 +125,16 @@ function box.on_reload_configuration()
end end
return unpack(range) return unpack(range)
end end
index_mt.select_reverse_range = function(index, limit, ...)
local range = {}
for k, v in index.idx.prev, index.idx, ... do
if #range >= limit then
break
end
table.insert(range, v)
end
return unpack(range)
end
-- --
local space_mt = {} local space_mt = {}
space_mt.len = function(space) return space.index[0]:len() end space_mt.len = function(space) return space.index[0]:len() end
...@@ -124,6 +143,9 @@ function box.on_reload_configuration() ...@@ -124,6 +143,9 @@ function box.on_reload_configuration()
space_mt.select_range = function(space, ino, limit, ...) space_mt.select_range = function(space, ino, limit, ...)
return space.index[ino]:select_range(limit, ...) return space.index[ino]:select_range(limit, ...)
end end
space_mt.select_reverse_range = function(space, ino, limit, ...)
return space.index[ino]:select_reverse_range(limit, ...)
end
space_mt.select_limit = function(space, ino, offset, limit, ...) space_mt.select_limit = function(space, ino, offset, limit, ...)
return box.select_limit(space.n, ino, offset, limit, ...) return box.select_limit(space.n, ino, offset, limit, ...)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment