Fix table.binary_search, add table.map_keys

This commit is contained in:
Lars Mueller 2020-10-06 19:13:25 +02:00
parent 3c91dbdeb8
commit b912582199

@ -148,6 +148,14 @@ function map(t, func)
return t
end
function map_keys(tab, func)
local new_tab = {}
for key, value in pairs(tab) do
new_tab[func(key)] = value
end
return new_tab
end
function process(t, func)
local r={}
for k, v in pairs(t) do
@ -315,7 +323,7 @@ end
function binary_search_comparator(comparator)
-- if found, returns index; if not found, returns -index for insertion
function binary_search(list, value)
return function(list, value)
local min, max = 1, #list
while min <= max do
local pivot = min + math.floor((max-min)/2)