mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
[added] tablex.swap
This commit is contained in:
parent
87834e9267
commit
5cd33398a5
@ -48,6 +48,12 @@ function tablex.unshift(t, v)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--swap two indices of a table
|
||||||
|
--(easier to read and generally less typing than the common idiom)
|
||||||
|
function tablex.swap(t, i, j)
|
||||||
|
t[i], t[j] = t[j], t[i]
|
||||||
|
end
|
||||||
|
|
||||||
--insert to the first position before the first larger element in the table
|
--insert to the first position before the first larger element in the table
|
||||||
--if this is used on an already sorted table, the table will remain sorted and not need re-sorting
|
--if this is used on an already sorted table, the table will remain sorted and not need re-sorting
|
||||||
--todo: make it do binary search rather than linear to improve performance
|
--todo: make it do binary search rather than linear to improve performance
|
||||||
|
Loading…
Reference in New Issue
Block a user