-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtest_ts.lua
More file actions
45 lines (34 loc) · 797 Bytes
/
test_ts.lua
File metadata and controls
45 lines (34 loc) · 797 Bytes
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
42
43
44
45
local zset = require "zset"
local total = 100
local function random_choose(t)
if #t == 0 then
return
end
local i = math.random(#t)
return table.remove(t, i)
end
local function delete_handler(member)
print("delete", member)
end
local zs = zset.new(delete_handler)
local score = 100
for i=1, total do
local name = "a" .. i
local a = i % 2 ~= 0 and score or score/ 2
zs:add(a, name, i)
end
assert(total == zs:count())
print("rank 28:", zs:rank("a28"))
print("rev rank 28:", zs:rev_rank("a28"))
local t = zs:range(1, 10)
print("rank 1-10:")
for _, name in ipairs(t) do
print(name)
end
local t = zs:rev_range(1, 10)
print("rev rank 1-10:")
for _, name in ipairs(t) do
print(name)
end
print("------------------ dump ------------------")
zs:dump()