HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

SortUtils

10-09-2009, 01:35 PM#1
grim001
SortUtils allows you sort arrays of reals, units and structs efficiently.

-It uses a QuickSort/InsertionSort hybrid.
-It is based on dynamic arrays and array pointers.
-It can sort a real array from least to greatest. (Read backwards for greatest to least).
-It can sort a unit array or struct array according to the values in a parallel real array.
-It can sort a unit array or struct array according to a SortFunc that can specify any sorting criteria.

The documentation is like a novel; be warned.

Expand JASS:
10-12-2009, 07:10 PM#2
Rising_Dusk
I was going over this and it is actually rather cool. I don't have the time to verify that it does all of the things that it says it does, but if you respond to this and say that it does, that'll be good enough.

Once you do that, I think I will approve this. I really like the API and it could prove incredibly useful for people. I also really like how thorough the documentation is, I know exactly how to use this library after having read it.
10-12-2009, 07:15 PM#3
Anachron
This is kinda cool, I see many uses right now, just think about it:

An system to sort for best players (in a hero arena or in general)
For closest distance units.
... and even more.

This might be in my new AoS, if it works without bugs.
10-12-2009, 10:20 PM#4
grim001
I originally created this because I needed fast distance sorting for an aura system, but eventually I came up with this way to generalize it, so I'm happy with the way it turned out.

I did try partially-recursive and non-recursive variations on quicksort, and it didn't do any better than this recursive implementation in benchmarks. I always assumed that recursive algorithms would be slow in JASS, but they seem to do alright.

I tested it heavily so I know that each function does what it says it does. There shouldn't be any bugs, as they'd wind up being incredibly apparent given the nature of this library.
10-13-2009, 02:15 AM#5
Rising_Dusk
Then I do declare this approved.
10-28-2009, 05:11 PM#6
grim001
Updated.
  • If you intend to use SortUtils with a library that makes heavy use of dynamic arrays and you are worried about instance limits, a special textmacro has been provided to solve that problem. If you use this textmacro within a scope or library, the RealArrays/UnitArrays/StructArrays used within that scope or library will magically have their own instance limit. The textmacro must be placed above any calls to the SortUtils API. Also, you will be required to declare a private constant integer MaxArraySize within that scope or library, which will be used within it.
11-20-2009, 09:00 AM#7
grim001
Updated.
  • Documentation, code and efficiency improvements.

Nested textmacros will let me cut the size of the library in half, so it will probably get another update once those come out.
11-24-2009, 06:47 AM#8
Tot
Expand SortUtils-Code:

hasn't it to be UnitArray/StructArray?


anyway, this is really cool, but I'd make a textmacro to let the user sort every thing from integer to lightnings and back
some kind of //! textmacro SortUtils takes TYPE, NULL, SCOPE
you're using introsort and I've read on wikipedia, that it works best with a Threshold of 16
11-24-2009, 08:11 AM#9
grim001
Quote:
Originally Posted by Tot
I'd make a textmacro to let the user sort every thing from integer to lightnings and back
If you want to sort stuff other than reals or units, that's what StructArrays are for. The whole point of this is to not be one of those lame textmacro-based sorting libraries.

Also, updated.
  • Altered the sorting algorithm. Everything sorts about 15% faster now.
  • Set the default threshold to 16 for some reason.
05-23-2011, 02:35 AM#10
SanKakU
i like this. should save me time with the computer sorting things for me :)