merged gui

This commit is contained in:
monica
2023-01-07 12:04:08 -05:00
committed by Monica Moniot
parent 2e021267e4
commit 1821dc1ccc
18 changed files with 2308 additions and 1 deletions

View File

@@ -49,3 +49,46 @@ end
function irpairs(a)
return irnext, a, 0
end
---@generic V
---@param arr Array<V>
---@param comp fun(a: V, b: V) A comparison function for sorting. Must return truthy if `a < b`.
function stable_sort(arr, comp)
local size = #arr
for i = 2, size do
local a = arr[i]
local j = i
while j > 1 do
local b = arr[j - 1]
if comp(a, b) then
arr[j] = b
j = j - 1
else
break
end
end
arr[j] = a
end
end
---@param values number[]
---@param keys any[]
function dual_sort(values, keys)
local size = #values
for i = 2, size do
local a = values[i]
local j = i
while j > 1 do
local b = values[j - 1]
if a < b then
values[j] = b
keys[j] = keys[j - 1]
j = j - 1
else
break
end
end
values[j] = a
keys[j] = keys[i]
end
end