aboutsummaryrefslogtreecommitdiffstats
path: root/util/set.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/set.lua')
-rw-r--r--util/set.lua19
1 files changed, 17 insertions, 2 deletions
diff --git a/util/set.lua b/util/set.lua
index b7345e7e..69dfef5d 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -6,8 +6,9 @@
-- COPYING file in the source package for more information.
--
-local ipairs, pairs, getmetatable, setmetatable, next, tostring =
- ipairs, pairs, getmetatable, setmetatable, next, tostring;
+local ipairs, pairs, setmetatable, next, tostring =
+ ipairs, pairs, setmetatable, next, tostring;
+local getmetatable = getmetatable;
local t_concat = table.concat;
local _ENV = nil;
@@ -51,6 +52,15 @@ local function new(list)
return items[item];
end
+ function set:contains_set(other_set)
+ for item in other_set do
+ if not self:contains(item) then
+ return false;
+ end
+ end
+ return true;
+ end
+
function set:items()
return next, items;
end
@@ -151,6 +161,11 @@ function set_mt.__div(set, func)
return new_set;
end
function set_mt.__eq(set1, set2)
+ if getmetatable(set1) ~= set_mt or getmetatable(set2) ~= set_mt then
+ -- Lua 5.3+ calls this if both operands are tables, even if metatables differ
+ return false;
+ end
+
set1, set2 = set1._items, set2._items;
for item in pairs(set1) do
if not set2[item] then