coll question

Davide Favargiotti's icon

hi
is there a simple way to sort data inside a coll object using more than one data position?
ex:
i have this kind of list:
1, A B C D (where A,B,C,D are numbers)
and i would like to order the data in ascending order first for A, than for B, than C and D.

at the end i would like to have a list ordered like this one:
1, 1 0 41 8
2, 1 0 59 3
3, 1 1 40 7
4, 1 1 57 1
5, 2 0 0 0

i cannot find an easy way to do that, and searching in the forum didn't help.

thank you in advance

davide

Davide Favargiotti's icon

this is the solution i came up:

Max Patch
Copy patch and select New From Clipboard in Max.

the list of number are converted to symbol and then a second coll object sort these symbol; then everything is converted back to list of number and substituted in the original coll.
any better ideas??
thank you
davide

Hans Höglund's icon

If the sort algorithm used in coll had been stable sort 4, sort 3, sort 1 etc. would have done it.

It would be nice if a stablesort message could be added to future versions.

Davide Favargiotti's icon

hi. back to work on this patch after some weeks, and found out that my solution posted above is not working properly.
2 is sorted after 12, not before (max see it as a symbol and so 2 is "bigger" the 1 in 12).
any ideas?

Bas van der Graaff's icon

Hans, do you have experience with the sort message crashing Max or not working properly? Then i'd like to find out more about that...I do use 'sort -1 -1' occasionally. Generally not in a metro or loop, but I'd like to know if are any problems with it. I can't recall ever having problems with coll, except for the obviously not working linkedlist functionality of the thing. Thanks!

andrea agostini's icon

if instead than [tosymbol] you use something like [sprintf symout %04d %04d %04d %04d] that should do the trick.

but beware:
it only works with integers > -1000 and < 10000 (that is, up to 4 characters). to allow for a greater range, change %04d into %05d or more. If you want to do it with floats, besides changing the other relevant objects in the patch, you should substitute %04d with something like %010.05f

moreover, if you use it a real lot it will end up clogging the Max's symbol table (poor performance, high memory usage...)

hope it helps, though
aa

andrea agostini's icon

(it was @davide, of course!)

Davide Favargiotti's icon

thank you andrea, i think that should do the work... i'll try and let you know. i use it only for sort timecode data inside a coll, so it shouldn't be to much data (and only 2 characters).
if i clean the "sorting coll" at the end of every sorting process, will the max symbol table be cleaned to?
thanks

davide

andrea agostini's icon

no, there is no way to clean up the symbol table. every new symbol you create stays there until you quit Max.

Davide Favargiotti's icon

mmm... how does this symbol table things work? every new symbol will eat some memory, or only symbol that doesn't exist before: ie "5" count only one, even if I convert the integer to symbol every second (but it's always "5") or every time I ask a conversion into symbol max will eat some resources?

Bas van der Graaff's icon

What you said first...if you convert the same thing to symbol every second it will use the same symbol from the symbol table (that is, the pointer to the same string). This speeds things up quite a lot, since you're generally using the same strings a lot.

But that's also why converting lists from a coll to string every frame will start to take up a lot of memory, because they will generally be different every time.