aboutsummaryrefslogtreecommitdiff
path: root/lua/trie.lua
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-10-18 14:27:02 -0700
committerGitHub <noreply@github.com>2019-10-18 14:27:02 -0700
commit6c3d4e4b4ce8a4eb0b5ac012e38ca1f66af4b077 (patch)
treea13787a3bbac64a82ee95ba14fcc75ff2cad4a69 /lua/trie.lua
parentAllow excluding files from highlight with '*' (#11) (diff)
Update color functions (#13)
- Add hsl, hsla, rgba, RRGGBBAA - Redo the parser for rgb,rgba,hsl,hsla codes. - Fix the trie implementation. - Bugfix and refactor alpha/error handling
Diffstat (limited to 'lua/trie.lua')
-rw-r--r--lua/trie.lua40
1 files changed, 21 insertions, 19 deletions
diff --git a/lua/trie.lua b/lua/trie.lua
index b0751aa..e74d9eb 100644
--- a/lua/trie.lua
+++ b/lua/trie.lua
@@ -30,6 +30,7 @@ void free(void *ptr);
local Trie_t = ffi.typeof('struct Trie')
local Trie_ptr_t = ffi.typeof('$ *', Trie_t)
+local Trie_size = ffi.sizeof(Trie_t)
local function byte_to_index(b)
-- 0-9 starts at string.byte('0') == 0x30 == 48 == 0b0011_0000
@@ -75,8 +76,6 @@ local function verify_byte_to_index()
end
end
-local Trie_size = ffi.sizeof(Trie_t)
-
local function new_trie()
local ptr = ffi.C.malloc(Trie_size)
ffi.fill(ptr, Trie_size)
@@ -237,6 +236,9 @@ local function print_structure(s)
end
local function free_trie(trie)
+ if trie == nil then
+ return
+ end
for i = 0, 61 do
local child = trie.character[i]
if child ~= nil then
@@ -247,24 +249,24 @@ local function free_trie(trie)
end
local Trie_mt = {
- __index = {
- insert = insert;
- search = search;
- longest_prefix = longest_prefix;
- };
- __tostring = function(trie)
- local structure = trie_structure(trie)
- if structure then
- return table.concat(print_structure(structure), '\n')
- else
- return 'nil'
- end
- end;
- __gc = free_trie;
- }
-local Trie = ffi.metatype(Trie_t, Trie_mt)
+ __new = new_trie;
+ __index = {
+ insert = insert;
+ search = search;
+ longest_prefix = longest_prefix;
+ };
+ __tostring = function(trie)
+ local structure = trie_structure(trie)
+ if structure then
+ return table.concat(print_structure(structure), '\n')
+ else
+ return 'nil'
+ end
+ end;
+ __gc = free_trie;
+}
-return Trie
+return ffi.metatype('struct Trie', Trie_mt)
-- local tests = {
-- "cat";