2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 local select = select;
12 local t_insert = table.insert;
18 local function get(self, ...)
20 for n = 1,select('#', ...) do
21 t = t[select(n, ...)];
22 if not t then break; end
27 local function add(self, ...)
29 local count = select('#', ...);
31 local key = select(n, ...);
33 if not tab then tab = {}; t[key] = tab; end
36 t_insert(t, (select(count, ...)));
39 local function set(self, ...)
41 local count = select('#', ...);
43 local key = select(n, ...);
45 if not tab then tab = {}; t[key] = tab; end
48 t[(select(count-1, ...))] = (select(count, ...));
51 local function r(t, n, _end, ...)
52 if t == nil then return; end
53 local k = select(n, ...);
67 for _,b in pairs(t) do
76 local function remove(self, ...)
77 local _end = select('#', ...);
79 if select(n, ...) then _end = n; break; end
81 r(self.data, 1, _end, ...);
85 local function s(t, n, results, _end, ...)
86 if t == nil then return; end
87 local k = select(n, ...);
90 for _, v in pairs(t) do
94 t_insert(results, t[k]);
101 s(v, n+1, results, _end, ...);
104 for _,b in pairs(t) do
105 s(b, n+1, results, _end, ...);
110 -- Search for keys, nil == wildcard
111 local function search(self, ...)
112 local _end = select('#', ...);
114 if select(n, ...) then _end = n; break; end
117 s(self.data, 1, results, _end, ...);
121 -- Append results to an existing list
122 local function search_add(self, results, ...)
123 if not results then results = {}; end
124 local _end = select('#', ...);
126 if select(n, ...) then _end = n; break; end
128 s(self.data, 1, results, _end, ...);
140 search_add = search_add;