Module:TableTools: Difference between revisions

use fooBar for function names instead of getFooBar
(remove an unnecessary table.sort from compressSparseArray)
(use fooBar for function names instead of getFooBar)
Line 35:
--[[
------------------------------------------------------------------------------------
-- getUnionunion
--
-- This returns the union of the values of n tables, as an array. For example, for
-- the tables {1, 3, 4, 5, foo = 7} and {2, bar = 3, 5, 6}, getUnionunion will return
-- {1, 2, 3, 4, 5, 6, 7}.
------------------------------------------------------------------------------------
--]]
function p.getUnionunion(...)
local tables = {...}
local vals, ret = {}, {}
Line 59:
--[[
------------------------------------------------------------------------------------
-- intersection
-- getIntersection
--
-- This returns the intersection of the values of n tables, as an array. For
-- example, for the tables {1, 3, 4, 5, foo = 7} and {2, bar = 3, 5, 6},
-- getIntersectionintersection will return {3, 5}.
------------------------------------------------------------------------------------
--]]
function p.getIntersectionintersection(...)
local tables = {...}
local vals, ret = {}, {}
Line 87:
--[[
------------------------------------------------------------------------------------
-- getNumKeysnumKeys
--
-- This takes a table and returns an array containing the numbers of any numerical
Line 93:
------------------------------------------------------------------------------------
--]]
function p.getNumKeysnumKeys(t)
local isPositiveInteger = p.isPositiveInteger
local nums = {}
Line 107:
--[[
------------------------------------------------------------------------------------
-- affixNums
-- getAffixNums
--
-- This takes a table and returns an array containing the numbers of keys with the
-- specified prefix and suffix. For example, for the table
-- {a1 = 'foo', a3 = 'bar', a6 = 'baz'} and the prefix "a", getAffixNumsaffixNums will
-- return {1, 3, 6}.
------------------------------------------------------------------------------------
--]]
function p.getAffixNumsaffixNums(t, prefix, suffix)
prefix = prefix or ''
suffix = suffix or ''
Line 142:
function p.compressSparseArray(t)
local ret = {}
local nums = p.getNumKeysnumKeys(t)
for _, num in ipairs(nums) do
ret[#ret + 1] = t[num]
Line 158:
--]]
function p.sparseIpairs(t)
local nums = p.getNumKeysnumKeys(t)
local i = 0
local lim = #nums
Anonymous user