Software /
code /
prosody
Comparison
util/set.lua @ 6679:96e034508978
Merge 0.10->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 13 May 2015 17:00:27 +0100 |
parent | 6675:cb5b56ddabfd |
child | 6777:5de6b93d0190 |
comparison
equal
deleted
inserted
replaced
6666:42fdc8dddf04 | 6679:96e034508978 |
---|---|
32 end | 32 end |
33 end | 33 end |
34 return new_set; | 34 return new_set; |
35 end | 35 end |
36 function set_mt.__eq(set1, set2) | 36 function set_mt.__eq(set1, set2) |
37 local set1, set2 = set1._items, set2._items; | 37 set1, set2 = set1._items, set2._items; |
38 for item in pairs(set1) do | 38 for item in pairs(set1) do |
39 if not set2[item] then | 39 if not set2[item] then |
40 return false; | 40 return false; |
41 end | 41 end |
42 end | 42 end |
64 | 64 |
65 function new(list) | 65 function new(list) |
66 local items = setmetatable({}, items_mt); | 66 local items = setmetatable({}, items_mt); |
67 local set = { _items = items }; | 67 local set = { _items = items }; |
68 | 68 |
69 -- We access the set through an upvalue in these methods, so ignore 'self' being unused | |
70 --luacheck: ignore 212/self | |
71 | |
69 function set:add(item) | 72 function set:add(item) |
70 items[item] = true; | 73 items[item] = true; |
71 end | 74 end |
72 | 75 |
73 function set:contains(item) | 76 function set:contains(item) |
80 | 83 |
81 function set:remove(item) | 84 function set:remove(item) |
82 items[item] = nil; | 85 items[item] = nil; |
83 end | 86 end |
84 | 87 |
85 function set:add_list(list) | 88 function set:add_list(item_list) |
86 if list then | 89 if item_list then |
87 for _, item in ipairs(list) do | 90 for _, item in ipairs(item_list) do |
88 items[item] = true; | 91 items[item] = true; |
89 end | 92 end |
90 end | 93 end |
91 end | 94 end |
92 | 95 |