coll question

Feb 25, 2010 at 6:17pm

coll question

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

#48778
Feb 26, 2010 at 4:22pm

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

#175310
Feb 27, 2010 at 12:50pm

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.

#175311
May 12, 2010 at 3:14pm

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?

#175312
May 12, 2010 at 3:59pm

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!

#175313
May 12, 2010 at 4:19pm

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

#175314
May 12, 2010 at 4:20pm

(it was @davide, of course!)

#175315
May 12, 2010 at 4:25pm

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

#175316
May 12, 2010 at 5:23pm

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

#175317
May 12, 2010 at 10:25pm

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?

#175318
May 13, 2010 at 8:31am

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.

#175319

You must be logged in to reply to this topic.