table.sort
Posted: 16 Sep 2015 00:47
Has run into the lua table library sort function not being completely reliable?
I have been sorting a list of id / tag pairs, and I wanted the sort to be first by id and then by tag, with the wrinkle that Name would always come first. It works fine except for an occasional few cases where the name did not come first. I debugged the sort function and could not spot it making any mistakes. I then knocked up a bubble sort and used that instead, and no mistakes.
The attached plugin takes one of my errant data sets and sorts it both ways, and you can see the third and fourth items are incorrect with table.sort and correct with the bubble. Counting the calls to the sort function shows up the inefficiency of the bubble - but accuracy is the first priority!
I have been sorting a list of id / tag pairs, and I wanted the sort to be first by id and then by tag, with the wrinkle that Name would always come first. It works fine except for an occasional few cases where the name did not come first. I debugged the sort function and could not spot it making any mistakes. I then knocked up a bubble sort and used that instead, and no mistakes.
The attached plugin takes one of my errant data sets and sorts it both ways, and you can see the third and fourth items are incorrect with table.sort and correct with the bubble. Counting the calls to the sort function shows up the inefficiency of the bubble - but accuracy is the first priority!