Module:Sandbox/Alexiscoutinho/Lua set: Difference between revisions

Content deleted Content added
Created page with 'require('Module:Lua class') local libraryUtil = require('libraryUtil') local TableTools = require('Module:TableTools/sandbox') -- Note: hash collisions are not handled yet frozenset = class('frozenset', { __init = function (self, args) local elements = {} if #args == 0 then -- for performance self._elements = elements return elseif #args == 1 then local arg = args[1] if type(arg) == 'string' then for i = 1, mw.ustring.len(arg) do...'
 
Fixed hashable checking
Line 61:
 
_get = function (elements, elem)
if pcallisinstance(elem) and elem.hash) then
return elements[elem.hash()]
else
Line 69:
 
_set = function (elements, elem)
if pcallisinstance(elem) and elem.hash) then
elements[elem.hash()] = elem -- otherwise different objects with the same content would duplicate
else
Line 236:
set = class('set', frozenset, {
_del = function (elements, elem)
if pcallisinstance(elem) and elem.hash) then
elements[elem.hash()] = nil
else