Forums > MaxMSP

### coll question

Feb 25 2010 | 6:17 pm

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.

davide

Feb 26 2010 | 4:22 pm

this is the solution i came up:

— Pasted Max Patch, click to expand. —

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

Feb 27 2010 | 12:50 pm

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.

May 12 2010 | 3:14 pm

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?

May 12 2010 | 3:59 pm

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!

May 12 2010 | 4:19 pm

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

May 12 2010 | 4:20 pm

(it was @davide, of course!)

May 12 2010 | 4:25 pm

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

May 12 2010 | 5:23 pm

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

May 12 2010 | 10:25 pm

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?

May 13 2010 | 8:31 am

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.

Viewing 11 posts - 1 through 11 (of 11 total)

Forums > MaxMSP