-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_core.lua
More file actions
42 lines (34 loc) · 894 Bytes
/
Copy pathtest_core.lua
File metadata and controls
42 lines (34 loc) · 894 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
local rax_core = require "rax.core"
local rtree = rax_core.new()
local it = rax_core.newit(rtree)
rax_core.insert(rtree, "/blog/foo/", 1)
rax_core.insert(rtree, "/blog/foo/a/", 2)
rax_core.insert(rtree, "/blog/foo/c/", 3)
rax_core.insert(rtree, "/blog/foo/bar", 4)
local idx = rax_core.find(rtree, "/blog/foo/bar")
assert(idx == 4)
local function match(path)
local ret = rax_core.search(it, path)
if not ret then
error("search failed.")
end
while true do
local idx = rax_core.prev(it, path)
if idx <= 0 then
break
end
print(idx)
return idx
end
end
local path = "/blog/foo/a/b/c"
local idx = match(path)
assert(idx == 2)
local path = "/blog/foo/c/d"
local idx = match(path)
assert(idx == 3)
local path = "/blog/foo/xloo"
local idx = match(path)
assert(idx == 1)
rax_core.dump(rtree)
rax_core.destroy(rtree)