| 1 | function mminsert(tbl, key, value) | 
| 2 |   if tbl[key] == nil then tbl[key] = {} end
 | 
| 3 | table.insert(tbl[key], value) | 
| 4 | end | 
| 5 | |
| 6 | function mmcontains(tbl, key, value) | 
| 7 | if tbl[key] ~= nil then | 
| 8 | for _, v in ipairs(tbl[key]) do | 
| 9 | if v == value then return true end | 
| 10 | end | 
| 11 | end | 
| 12 | return false | 
| 13 | end | 
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #389 | 
| Snippet name: | mminsert / mmcontains (multimap functions) | 
| Eternal ID of this version: | #389/1 | 
| Text MD5: | 783c117c561a8361c5c6bee660586c7c | 
| Author: | stefan | 
| Category: | table functions | 
| Type: | Lua code | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2015-03-11 18:22:09 | 
| Source code size: | 300 bytes / 13 lines | 
| Pitched / IR pitched: | No / Yes | 
| Views / Downloads: | 888 / 242 | 
| Referenced in: | [show references] |