diff options
author | Matthew Wild <mwild1@gmail.com> | 2014-04-02 17:41:38 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2014-04-02 17:41:38 +0100 |
commit | 27b4049481f29dcac2d6093c40ad7e8bf1ea8899 (patch) | |
tree | 39ca42dddf3935546a0c3c37b2e2456a554899f1 /util/set.lua | |
parent | ae885de6a2f36eacd6085e7582e5019882208d23 (diff) | |
parent | 8c0d996be4f47b77a02668474d3d8a0a41bd0f98 (diff) | |
download | prosody-27b4049481f29dcac2d6093c40ad7e8bf1ea8899.tar.gz prosody-27b4049481f29dcac2d6093c40ad7e8bf1ea8899.zip |
Merge 0.9->0.10
Diffstat (limited to 'util/set.lua')
-rw-r--r-- | util/set.lua | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/util/set.lua b/util/set.lua index fa065a9c..04f5f0f4 100644 --- a/util/set.lua +++ b/util/set.lua @@ -1,7 +1,7 @@ -- Prosody IM -- Copyright (C) 2008-2010 Matthew Wild -- Copyright (C) 2008-2010 Waqas Hussain --- +-- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- @@ -40,13 +40,13 @@ function set_mt.__eq(set1, set2) return false; end end - + for item in pairs(set2) do if not set1[item] then return false; end end - + return true; end function set_mt.__tostring(set) @@ -65,23 +65,23 @@ end function new(list) local items = setmetatable({}, items_mt); local set = { _items = items }; - + function set:add(item) items[item] = true; end - + function set:contains(item) return items[item]; end - + function set:items() - return items; + return next, items; end - + function set:remove(item) items[item] = nil; end - + function set:add_list(list) if list then for _, item in ipairs(list) do @@ -89,7 +89,7 @@ function new(list) end end end - + function set:include(otherset) for item in otherset do items[item] = true; @@ -101,22 +101,22 @@ function new(list) items[item] = nil; end end - + function set:empty() return not next(items); end - + if list then set:add_list(list); end - + return setmetatable(set, set_mt); end function union(set1, set2) local set = new(); local items = set._items; - + for item in pairs(set1._items) do items[item] = true; end @@ -124,14 +124,14 @@ function union(set1, set2) for item in pairs(set2._items) do items[item] = true; end - + return set; end function difference(set1, set2) local set = new(); local items = set._items; - + for item in pairs(set1._items) do items[item] = (not set2._items[item]) or nil; end @@ -142,13 +142,13 @@ end function intersection(set1, set2) local set = new(); local items = set._items; - + set1, set2 = set1._items, set2._items; - + for item in pairs(set1) do items[item] = (not not set2[item]) or nil; end - + return set; end |