Re: table.sort: invalid order function for sorting
"'Sewbacca' via lua-l" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
Would it be possible to make table.sort stable via this trick?
local t = ...
local orig = {}
for i,v in ipairs(t) do orig[v] = i end
table.sort(t, function(a, b)
if a == b then return orig[a] < orig[b] end
return a < b
end)
assume t is a table of objects with valid __le and __eq meta fields.
I suspect for large n that the runtime wouldn't be particularily good.
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/0cd00f9b-6158-4c5a-a2d8-d8f79fac29d6%40kolabnow.com.