Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #389 // mminsert / mmcontains (multimap functions)

Lua code

function mminsert(tbl, key, value)
  if tbl[key] == nil then tbl[key] = {} end
  table.insert(tbl[key], value)
end

function mmcontains(tbl, key, value)
  if tbl[key] ~= nil then
    for _, v in ipairs(tbl[key]) do
      if v == value then return true end
    end
  end
  return false
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: 659 / 188
Referenced in: #476 - Haiku font recognizer (collecting data)
#520 - Backport keywords from new case to known case
#3000382 - Answer for ferdie (>> t = 1, f = 0)