I tried experimenting by using >= but this will result in an error. Any approach suggested to solve this is appreciated! I am hoping for a simple solution before i start to remake my routines too much.
EDIT: Solved.
table.sort(map_table, function(b, a)
if a.size == b.size then return a.original_position > b.original_position
else return a.size < b.size
end
end)
“The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.” [Source. ]
Google search says this is done “on purpose for speed” and that “you should write your own sort”, or something.
Not sure if this is your problem. I looked at the code and can confirm the bug. I don’t have an easy workaround. I did notice that if I do the following map_size() at around line ~78
local tmp = { }
for _,val in ipairs(map_table) do
table.insert(tmp, val.size)
end
table.sort(tmp)
rprint(tmp)