Sorting Tables - One method

ArmellineArmelline Member, PRO Posts: 5,397

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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Very cool! Love this!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881

    Thanks @Armelline
    Very Generous of you!

  • thatguyontherightthatguyontheright Member Posts: 5

    Thanks a lot man.

  • NBWNBW Member, PRO Posts: 8

    @Armelline This is very exciting! How can I get hold of a copy of this example? Many thanks

  • ArmellineArmelline Member, PRO Posts: 5,397

    Hey @NBW. It was attached to the post but with the recent forum move attachments seem to be (hopefully temporarily) missing. I'm pretty sure this was the right file.


  • Two.ETwo.E Member Posts: 599

    Awesome. Checking out now. Love some Table work magic!

  • BinnyBinny Seoul, KoreaMember, PRO Posts: 75
    edited April 2020

    Great!! This is a big help to ranking system. Thank you.

    For reference, it took 0.617 sec on 30 rows.

  • NBWNBW Member, PRO Posts: 8

    Hi @Armelline - very elegant - works perfectly. This will be a huge help in my apps. Thanks again.

  • CasualEvolutionCasualEvolution Member, PRO Posts: 543

    Thanks @Armelline

    I have not yet come across the need to order a table, not at least that big! :)


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

    I'm dying of curiosity in which you walk! Hahaha

  • ArmellineArmelline Member, PRO Posts: 5,397

    @CasualEvolution - Something for a client, so don't want to go into lots of details, but essentially it's a history of games played. That's as big as we let the tables get before resetting them and only one had got that big, though! I didn't even realise any had got that big until the sorting became unreliable, which is what prompted me to try to find a better way!

Sign In or Register to comment.