diff options
Diffstat (limited to 'util/set.lua')
-rw-r--r-- | util/set.lua | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/util/set.lua b/util/set.lua index 08361d03..67f3dcaa 100644 --- a/util/set.lua +++ b/util/set.lua @@ -1,3 +1,5 @@ +local ipairs, pairs = + ipairs, pairs; module "set" @@ -5,40 +7,44 @@ function new(list) local items = {}; local set = { items = items }; - function set:add(set, item) + function set:add(item) items[item] = true; end - function set:contains(set, item) - return items[item] + function set:contains(item) + return items[item]; end - function set:items(set) + function set:items() return items; end - function set:remove(set, item) + function set:remove(item) items[item] = nil; end - function set:add_list(set, list) + function set:add_list(list) for _, item in ipairs(list) do items[item] = true; end end - function set:include(set, otherset) + function set:include(otherset) for item in pairs(otherset) do items[item] = true; end end - function set:exclude(set, otherset) + function set:exclude(otherset) for item in pairs(otherset) do items[item] = nil; end end + if list then + set:add_list(list); + end + return set; end |