1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
function index_random_test(space, index_no)
local COUNT = 128 -- enough to resize both sptree and mhash
-- clear the space
space:truncate()
-- randomize
math.randomseed(os.time())
-- insert values into the index
for k=1,COUNT,1 do space:insert{k} end
-- delete some values from the index
for i=1,COUNT/2,1 do
local k = math.random(COUNT)
local tuple = space:delete{k}
if tuple ~= nil then COUNT = COUNT - 1 end
end
local rnd_start = math.random(4294967296)
-- try to get all values from the index using index.random
local tuples = {}
local found = 0
while found < COUNT do
local rnd = math.random(4294967296)
if rnd == rnd_start then
error('too many iterations')
return nil
end
local tuple = space.index[index_no]:random(rnd)
if tuple == nil then
error('nil returned')
return nil
end
local k = tuple[1]
if tuples[k] == nil then
found = found + 1
end
tuples[k] = 1
end
return true
end
|