mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34:35 +00:00
Added tablex.swap_and_pop
This commit is contained in:
parent
0bc9ccb17b
commit
9b95643e6e
@ -54,6 +54,13 @@ function tablex.swap(t, i, j)
|
|||||||
t[i], t[j] = t[j], t[i]
|
t[i], t[j] = t[j], t[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--swap the element at i to the back of the table, and remove it
|
||||||
|
--avoids linear cost of removal at the expense of messing with the order of the table
|
||||||
|
function tablex.swap_and_pop(t, i)
|
||||||
|
tablex.swap(t, i, #t)
|
||||||
|
return tablex.pop(t)
|
||||||
|
end
|
||||||
|
|
||||||
--default comparison; hoisted for clarity
|
--default comparison; hoisted for clarity
|
||||||
--(shared with sort.lua and suggests the sorted functions below should maybe be refactored there)
|
--(shared with sort.lua and suggests the sorted functions below should maybe be refactored there)
|
||||||
local function default_less(a, b)
|
local function default_less(a, b)
|
||||||
|
Loading…
Reference in New Issue
Block a user