is there a simple way to sort data inside a coll object using more than one data position?
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
this is the solution i came up:
----------begin_max5_patcher---------- 1422.3oc0ZskbihCE8a7pfhucmBIP7X1.yOyNnqtRI.EGMgGt.4zomt589.R BLxFLBGiMoREaKgPbzQ2W5x82aLrhJ9fTYY9Wle2zv32aLL3c0zggrsgUF9i 3TbEeXVYjpJ7Nh0Vw0XjOX79iSI3x1dyOjUbfkRX76AH68khbVE8+HM8E9js rWw.Y+ZOQ.CKKyeHuzdLK9UZ9tmKIwLwUA.656zLf+oC7IzVS.5I6taglvQS Qz+9sPeqdO3bbF+AX8OGhoIXy+tDmmP5AXZdKdgM88mMaZ9XqlzRN4m0OyyX ElYjYzvrBbdrRDNem0V42ZvP.TeJxeDJBckTD31QQ6MiKRSetpnjs7hO9BtQ H9f73MFgaBtVwGm9OdRojQjTR8rQSIuSJqnE48VcFVGAYfayxyDB4nDFBZ9x 0tGNqo5coEwuQ3v0tsyDxKyaVJ1SxOdG7Ap7g5Ho46KIUjbFlIAe+mL9PJ64 A2iTu7K3Xxn26EoYCqckzjh7FrnLCMc29TqU.D6wJvmOhb79AtYVQQZDt7cZ EMJknrkTKOiyoYXFgQE3BZ2cezr8kzblxbQxw0ywqUwk0hzJSk3JuOvURHuS iI+jlvdkOWGYMEay8DgTzzT5+RZbpZck05MDypekEUj1e.CZiZb0uQTA21SM bLUQjKWtz1o4KufSUEOUcDXcBVtrnxvVrLZsZI9w1qjWU8ANtevwMlMaFcJ1 DDJj58Fww3Yzo+mjOg2I9rwuf42.aMKI0O+HR4VyjCY6e.LrvPZq6UHP3k8B TryJhh4ypdj1vgdLI8X2Y1sVqF094njCXzkc+so3hrLhvHqk0MjNtfkw8332 Los+c+kybEZvBhz2YJ6hAeVCin6CsFUjmTXhFmOQeBeM8+WO9EFnI+5G90fe OjyEbsE+MNM6dczbSjNaG5qIcy6z3JBJNMhu2jzcvJxO+En6WJKxlJ5okxBg LxIGNk5MoDrW3WCJUZ3s59SnNBNTPnttSRnfUji8KYx8PRxuLgOlv6kbJ.x4 zI06QgeM3TVwiRq2oWhuPfo3SW+uFJ8M49wrWtetcdrlUPARoUwomPgmlyry 7Rg9rrauKTgemj7b8zVilmwLVIMp9r4U830dDqgEo9PPhz9z0Y2Vzi9jBSxy dy5PBAOzyHHVciyD1ZEGuilqUWsjUVp05hto6LqMc3MYS+Xp+Ro4ikEMNVat 9vLTUwgx31UoLGTlp3NgTwn4c4C86Gi35jA9JMIQMwi78.Zx9h5nnk3y7GZs kNWX2XsRKbCVUvNPW51ccw1gZB6.v5C2.cwMXcgant3Fttvsit31YcgaWcws 65A2AZpWNfhvCG2.cwMbcgant31YcgaGcws65xKu1xIWgeG4qKOPbTofyZ.8 74m0me5IdiEZkB0Mt.+UkCVOcimYf30dj3FoafAdqq.CP5FHl25JPrADaGF2 n0kipf4.6qft83FVbQsu2U0eCr4FgbEu46lFKkZrthUCDvwib6Anq4ml2a8Z 6zq53OFbkl6a8gIKAE+AZIc8EJRLXSqkZSxYg8Q.fGWCcZKK4BxeoWPxME4N kMr+9lrkdKVYm0q5M5jW1154aWZQDNUVrecoAtqj0Frj2V3xjahpw6Byvlib xLqtywpK3dEqyhWWmxTt5cZk4njmUziupf4uziLb4ajQpXZ2YRMC8pNtP4uJ pjIYt3Go7Wct1JCddZOm71LTD83vRM+sBR+TiPRp+7HoTroLhgGEKtmayYXu bmIGnKjb5Gx1XINwWYP2CHYqCjturjyDPJDcWgTHRictvYRS.46cz24ITXXn uWicqw5xC8jussM.17Z04N8554Vr1zRD.d236Sj3tI5t9hPEB4AGfDgHnz.v ccHGFnKPgqmXWfEgbuGX62Cq19mf05F+Yy+iEdt4. -----------end_max5_patcher-----------
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??
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.
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).
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!
if instead than [tosymbol] you use something like [sprintf symout %04d %04d %04d %04d] that should do the trick.
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
(it was @davide, of course!)
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?
no, there is no way to clean up the symbol table. every new symbol you create stays there until you quit Max.
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?
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.
Forums > MaxMSP