Software /
code /
prosody
Changeset
905:6169597d5574
util.set: Fix to make constructor work, and functions defined correctly
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Mar 2009 12:37:56 +0000 |
parents | 904:0205dcd0854a |
children | 906:0831db62f134 |
files | util/set.lua |
diffstat | 1 files changed, 14 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/util/set.lua Sun Mar 22 12:13:39 2009 +0000 +++ b/util/set.lua Sun Mar 22 12:37:56 2009 +0000 @@ -1,3 +1,5 @@ +local ipairs, pairs = + ipairs, pairs; module "set" @@ -5,40 +7,44 @@ 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