Created
March 26, 2018 13:56
-
-
Save Adrodoc/04240602b32930b6d45bee62688fcde6 to your computer and use it in GitHub Desktop.
setmultimap.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- adrodoc55/setmultimap.lua | |
local pkg = {} | |
function pkg.put(multimap, key, value, hashfunction) | |
hashfunction = hashfunction or str | |
local set = multimap[key] or {} | |
local hash = hashfunction(value) | |
set[hash] = value | |
multimap[key] = set | |
end | |
function pkg.remove(multimap, key, value) | |
hashfunction = hashfunction or str | |
local set = multimap[key] | |
if set ~= nil then | |
local hash = hashfunction(value) | |
set[hash] = nil | |
if next(set) == nil then | |
multimap[key] = nil | |
end | |
end | |
end | |
return pkg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment