[PD] change list order according to their first element

Frank Barknecht fbar at footils.org
Tue Jul 27 15:36:43 CEST 2010


Hi,

On Tue, Jul 27, 2010 at 02:00:39PM +0100, Claude Heiland-Allen wrote:
> On 27/07/10 12:56, Libero Mureddu wrote:
> >Hello,
> >I'm trying to realize something like that: I have different lists that
> >I have to sort in ascending order according to their first element,
> >but I cannot find a solution.
> 
> It's a tricky one in vanilla Pd.

If the lists to sort always have the same structure, one could use data
structures for this. Attached is an example. Of course, appending the
data takes some time as well, and [append] doesn't like symbols, but
depending on what you want to do, this can be a fast, vanilla way to
sort lists. 

In the attachement, the lists are always "<number> a b c", but of course
the "a b c" part can change and will survive sorting.

Ciao
-- 
Frank
-------------- next part --------------
#N canvas 142 82 1000 479 10;
#N canvas 396 63 766 320 fixed-list 0;
#X obj 160 166 struct fixed-list float x symbol a symbol b symbol c
;
#X obj 31 142 tgl 15 0 empty empty visible? 17 7 0 10 -262144 -1 -1
0 1;
#X obj 31 166 drawnumber x -n;
#X obj 31 115 inlet;
#X connect 1 0 2 0;
#X connect 3 0 1 0;
#X restore 313 52 pd fixed-list;
#N canvas 0 0 450 300 data 0;
#X restore 312 83 pd data;
#X obj 174 242 pointer;
#X msg 174 216 traverse pd-data \, bang;
#X obj 44 269 append fixed-list x;
#X obj 44 237 list split 1;
#X obj 44 297 t b p;
#X msg 140 116 \; pd-data clear;
#X obj 44 352 set -symbol fixed-list a b c;
#X obj 44 87 t b b b;
#X obj 718 329 get fixed-list x a b c;
#X obj 718 374 pack f s s s;
#X obj 718 409 print SORTED;
#X obj 678 96 t b b b b;
#X obj 718 263 pointer;
#X msg 738 124 \; pd-data sort;
#X msg 718 168 traverse pd-data;
#X msg 678 229 next;
#X obj 678 205 until;
#X obj 44 162 until;
#X obj 44 189 random 1000;
#X obj 44 138 max;
#X msg 44 214 \$1 a b c;
#X obj 44 115 f 100;
#X obj 44 323 list append;
#X text 28 384 unfortunatly [append] doesn't seem to accept symbols
directly.;
#X text 418 55 structure of "list";
#X text 381 86 append pointers here.;
#X obj 44 39 bng 15 250 50 0 empty empty empty 17 7 0 10 -4034 -1 -1
;
#X msg 678 70 PRINT SORTED;
#X obj 678 46 bng 15 250 50 0 empty empty empty 17 7 0 10 -4034 -1
-1;
#X msg 44 60 MAKE 100 RANDOM "LISTS";
#X obj 313 31 tgl 15 0 empty empty visible? 17 7 0 10 -262144 -1 -1
0 1;
#X connect 2 0 4 1;
#X connect 3 0 2 0;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 5 1 24 1;
#X connect 6 0 24 0;
#X connect 6 1 8 3;
#X connect 9 0 23 0;
#X connect 9 1 3 0;
#X connect 9 2 7 0;
#X connect 10 0 11 0;
#X connect 10 1 11 1;
#X connect 10 2 11 2;
#X connect 10 3 11 3;
#X connect 11 0 12 0;
#X connect 13 0 18 0;
#X connect 13 2 16 0;
#X connect 13 3 15 0;
#X connect 14 0 10 0;
#X connect 14 1 18 1;
#X connect 16 0 14 0;
#X connect 17 0 14 0;
#X connect 18 0 17 0;
#X connect 19 0 20 0;
#X connect 20 0 22 0;
#X connect 21 0 19 0;
#X connect 22 0 5 0;
#X connect 23 0 21 0;
#X connect 24 0 8 0;
#X connect 28 0 31 0;
#X connect 29 0 13 0;
#X connect 30 0 29 0;
#X connect 31 0 9 0;
#X connect 32 0 0 0;


More information about the Pd-list mailing list