mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Fix table.binary_search, add table.map_keys
This commit is contained in:
parent
3c91dbdeb8
commit
b912582199
10
table.lua
10
table.lua
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user