Re: [PD] Re : Re : store and manipulate multiple lists

2012-03-18 Thread Frank Barknecht
Hi Benoît,

On Sat, Mar 17, 2012 at 01:26:35PM -0700, Benoît Fortier wrote:
 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!

Learning data structures is a bit confusing at first, but many typical 
operations
repeat again and again in almost the same way. It's like the [f ]x[+ 1] 
counter: At first it's 
hard to understand, but later you'll just do it without thinking.

Attached is a working sort patch.

Ciao
-- 
 Frank BarknechtDo You RjDj.me?  _ __footils.org__


sort-by-first-element-help.pd
Description: application/puredata


sort-by-first-element.pd
Description: application/puredata
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


[PD] Re : Re : store and manipulate multiple lists

2012-03-17 Thread Benoît Fortier
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!
BEnoît






 De : Frank Barknecht f...@footils.org
À : pd-list@iem.at 
Envoyé le : samedi 17 mars 2012 11h49
Objet : Re: [PD] Re : store and manipulate multiple lists
 
Hi,

On Thu, Mar 15, 2012 at 11:39:51AM +, Andy Farnell wrote:
 Yes of course. Once you can sort items of any type you can sort 
 aggregate items, structs, sublists  or whatever on one of their
 elements. Its a little messy in Pd. The best way might be to
 use pointers and try to do the classic Kernighan and Richie
 head swap thing but I have no idea how to exchange pointers in
 Pd.

Sorting lists of numbers by their first element is pretty easy to do
with Pd's data structures/pointers. I don't have Pd at hand now to patch
an example (maybe Monday), but basically you first define a data
structure with one float x field and one with an array of these
float-items in addition to its own float x. 

[pd $0-f]: 
    structure with one float item:
    [struct $0-f float x]

[pd $0-record]:
   structure with an x-float for sorting and the array data to hold
   all the list items:
   [struct $0-record float x array data $0-f]

Then you create the structured data from the lists and write them to a
subpatch as usual with data structures. The first element in an incoming
lists doubles as x position, the array holds the rest of the list.

   [r one-list]
   |
   [t a a a]
   |    |  |
   |    |  [list split 1]
   |    |  |                  ... traverse subpatch blabla
   |    |  [append $0-record x]
   |    |  |
   |    |  [s $0-current-pointer]
   |    |
   |    [list length]          [r $0-current-pointer]
   |    |                      |
   |    [setsize $0-record data]
   |
   [list-enumerate] - list-drip with index numbers, i.e. list a b - 0 a, 1 
b
   |
   [swap]                [r $0-current-pointer]
   |   \                 |
   [element $0-record data]
   |      \
   [set $0-f x]

Then sorting is just a message sort to the subpatch receiver,
afterwards dump the lists again using basically the opposite from above.
You're only interested in the data array now.

Ciao
-- 
Frank

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list