<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>I'm still not familiar with data structure and pointers in pd, but I think I'll use your suggestion as a starting point. Thanks!</span></div><div><span>BEnoît<br></span></div><div><br><span></span></div><div><br><span></span></div><div><span><br></span></div><div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1"> <b><span style="font-weight:bold;">De :</span></b> Frank Barknecht <fbar@footils.org><br> <b><span style="font-weight: bold;">À :</span></b> pd-list@iem.at <br> <b><span style="font-weight: bold;">Envoyé le :</span></b> samedi 17 mars 2012 11h49<br> <b><span style="font-weight: bold;">Objet :</span></b> Re: [PD]
Re : store and manipulate multiple lists<br> </font> </div> <br>Hi,<br><br>On Thu, Mar 15, 2012 at 11:39:51AM +0000, Andy Farnell wrote:<br>> Yes of course. Once you can sort items of any type you can sort <br>> aggregate items, structs, sublists or whatever on one of their<br>> elements. Its a little messy in Pd. The best way might be to<br>> use pointers and try to do the classic Kernighan and Richie<br>> head swap thing but I have no idea how to exchange pointers in<br>> Pd.<br><br>Sorting lists of numbers by their first element is pretty easy to do<br>with Pd's data structures/pointers. I don't have Pd at hand now to patch<br>an example (maybe Monday), but basically you first define a data<br>structure with one "float x" field and one with an array of these<br>float-items in addition to its own float x. <br><br> [pd $0-f]: <br> structure with one float item:<br> [struct $0-f float x]<br><br> [pd
$0-record]:<br> structure with an x-float for sorting and the array "data" to hold<br> all the list items:<br> [struct $0-record float x array data $0-f]<br><br>Then you create the structured data from the lists and write them to a<br>subpatch as usual with data structures. The first element in an incoming<br>lists doubles as "x" position, the array holds the rest of the list.<br><br> [r one-list]<br> |<br> [t a a a]<br> | | |<br> | | [list split 1]<br> | | | ... traverse subpatch blabla<br> | | [append $0-record x]<br> | | |<br> | | [s $0-current-pointer]<br> | |<br> | [list length] [r $0-current-pointer]<br> |
| |<br> | [setsize $0-record data]<br> |<br> [list-enumerate] <- list-drip with index numbers, i.e. "list a b" -> "0 a, 1 b"<br> |<br> [swap] [r $0-current-pointer]<br> | \ |<br> [element $0-record data]<br> | \<br> [set $0-f x]<br><br>Then sorting is just a message "sort" to the subpatch receiver,<br>afterwards dump the lists again using basically the opposite from above.<br>You're only interested in the "data" array now.<br><br>Ciao<br>-- <br>Frank<br><br>_______________________________________________<br><a ymailto="mailto:Pd-list@iem.at" href="mailto:Pd-list@iem.at">Pd-list@iem.at</a> mailing list<br>UNSUBSCRIBE and account-management -> <a
href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br><br><br> </div> </div> </div></body></html>