util.set: Fix to make constructor work, and functions defined correctly

This commit is contained in:
Matthew Wild 2009-03-22 12:37:56 +00:00
parent 7f87706ee4
commit 0cb055053f

View file

@ -1,3 +1,5 @@
local ipairs, pairs =
ipairs, pairs;
module "set" module "set"
@ -5,40 +7,44 @@ function new(list)
local items = {}; local items = {};
local set = { items = items }; local set = { items = items };
function set:add(set, item) function set:add(item)
items[item] = true; items[item] = true;
end end
function set:contains(set, item) function set:contains(item)
return items[item] return items[item];
end end
function set:items(set) function set:items()
return items; return items;
end end
function set:remove(set, item) function set:remove(item)
items[item] = nil; items[item] = nil;
end end
function set:add_list(set, list) function set:add_list(list)
for _, item in ipairs(list) do for _, item in ipairs(list) do
items[item] = true; items[item] = true;
end end
end end
function set:include(set, otherset) function set:include(otherset)
for item in pairs(otherset) do for item in pairs(otherset) do
items[item] = true; items[item] = true;
end end
end end
function set:exclude(set, otherset) function set:exclude(otherset)
for item in pairs(otherset) do for item in pairs(otherset) do
items[item] = nil; items[item] = nil;
end end
end end
if list then
set:add_list(list);
end
return set; return set;
end end