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"
@ -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