lua: Set and Sequence

This commit is contained in:
Emil Tin
2016-11-15 13:36:39 +01:00
committed by Patrick Niklaus
parent 24c2708d1e
commit 5d564ee510
3 changed files with 159 additions and 74 deletions
+10
View File
@@ -0,0 +1,10 @@
-- Sequence of items
-- Ordered, but no have to loop through items to check for inclusion.
-- Currently the same as a table.
function Sequence(source)
return source
end
return Sequence
+23
View File
@@ -0,0 +1,23 @@
-- Set of items
-- Fast check for inclusion, but unordered.
--
-- Instead of having to do:
-- whitelist = { 'apple'=true, 'cherries'=true, 'melons'=true }
--
-- you can do:
-- whitelist = Set { 'apple', 'cherries', 'melons' }
--
-- and then use it as:
-- print( whitelist['cherries'] ) => true
function Set(source)
set = {}
if source then
for i,v in ipairs(source) do
set[v] = true
end
end
return set
end
return Set