Sorting Tables - One method

ArmellineArmelline Member, PRO Posts: 5,354

I have to do quite a lot of stuff involving sorting tables, so I'm always on the lookout for new, faster ways of doing it. I've experimented a lot with bubble sorts in the past, as they're straightforward and easy to implememt in GameSalad, but the results have always been... meh. I could make them reasonably fast, but they'd become increasingly unresponsive the more data they were asked to sort, and if they were sorting tables with lots of columns, they'd get slower still. I tested methods posted by various users of the forums and none really offered the speed or responsiveness I needed.

In the end I abandoned the idea of bubble sorts, or sorting in ways that work well in other "programming languages" and decided to focus more on making use of the things GameSalad does well, rather than trying to shoehorn other methods in. I ended up with a method considerably faster than any I'd made before, or seen posted on the forums. I'm sure it's still nowhere near optimal, but I thought I'd share it anyway. The two key benefits of this method over others I've seen are that it will sort tables with lots of columns quite happily (my old method struggled with over 20 columns) and it gives a progress information (ish - it shows what % it has sorted but the time each % takes decreases each pass of the table).

It will sort the 23 column, 200 row demo table in under 5 seconds (on my computer and iPad, anyway). If you have a faster method, please let me know! Bumping up the loops per frame will speed things up further, but will depend on the device handling it.

I use this method to sort around ten thousand table rows, with ~50 columns, and it handles it like a champ.

Anyhow, hope this helps someone.

Comments

Sign In or Register to comment.