[PD] ordered numbers

Frank Barknecht fbar at footils.org
Sat Oct 22 10:00:10 CEST 2005


Hallo,
IOhannes m zmoelnig hat gesagt: // IOhannes m zmoelnig wrote:

> well, the subject of the mail was about "ordered" numbers, so i thought
> about sorting arbitrary numbers, not a fixed set.
> if you have a fixed set of numbers and want to do a mapping between
> those, your solution is surely the preferred way to go.

However if you use the old zexy sort, you can get at the indices using
the table-map approach as well. If you have four numbers in a vector
x, that is x[0],x[1],x[2],x[3], and if you then sort this, you are in
fact looking for the position, that each element in the sorted list,
had in the unsorted input vector x.

A very simple approach would be to store vector x into a table, then
for each element of the result list, look for the position of this
element by walking through [table x], compare every x[i] for equality
with the current output element, and store its "i"ndex.

Attached patch illustrates this. It's a bit complicated, uses [list]
again but only to do what [drip] does. For simplicity table length is
assumend to be 4, however with resizing tables etc. it could be made
to work for a changing number of input floats as well. 

Known bug: It fails, if the same input number occurs twice or more.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 576 27 615 650 10;
#X obj 136 178 sort;
#X obj 199 116 table x 4;
#X msg 158 90 0 \$1 \$2 \$3 \$4;
#X obj 158 116 s x;
#X obj 330 104 s x;
#X msg 330 81 const 0;
#N canvas 116 31 673 426 drip 0;
#X obj 19 287 list split 1;
#X obj 19 204 until;
#X obj 19 242 list append;
#X obj 45 171 t b l;
#X obj 149 287 bang;
#X msg 45 148 1 2 3 4 a b c;
#X text 34 21 example 3: serializing a message without delays;
#X text 17 55 The "until" object can be used as shown to iterate through
all the items of a list.;
#X text 178 147 <- click to test;
#X text 101 171 First store list \, then start the loop;
#X text 118 199 "until" bangs its output until told to stop by a "bang"
to its right inlet.;
#X text 137 241 Store the remaining list.;
#X text 194 286 third outlet of "split" tells us to stop.;
#X text 67 318 Second outlet of "split" becomes the new list for "list
append" above.;
#X text 75 377 First outlet is the output.;
#X obj 29 115 inlet;
#X obj 19 378 outlet;
#X connect 0 0 16 0;
#X connect 0 1 2 1;
#X connect 0 2 4 0;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 1 0;
#X connect 3 1 2 1;
#X connect 4 0 1 1;
#X connect 5 0 3 0;
#X connect 15 0 3 0;
#X restore 136 210 pd drip;
#X msg 136 331 4;
#X obj 136 289 t b f;
#N canvas 387 418 450 300 walk 0;
#X obj 134 143 f 0;
#X obj 162 141 + 1;
#X obj 130 94 until;
#X obj 129 66 t f b;
#X msg 173 92 0;
#X obj 133 38 inlet;
#X obj 134 184 outlet;
#X connect 0 0 1 0;
#X connect 0 0 6 0;
#X connect 1 0 0 1;
#X connect 2 0 0 0;
#X connect 3 0 2 0;
#X connect 3 1 4 0;
#X connect 4 0 0 1;
#X connect 5 0 3 0;
#X restore 136 355 pd walk;
#X obj 136 411 tabread x;
#X obj 136 377 t f f;
#X obj 136 493 f;
#X obj 136 439 ==;
#X obj 136 466 select 1;
#X obj 136 519 print result;
#X obj 136 64 t a a b;
#X msg 136 38 2 4 3 10;
#X text 206 353 count from 0-4 \, used to walk along input vector;
#X text 206 441 If this is equal \, we have found the occurence of
the current output value in the input;
#X text 211 495 and we can print the current index in x.;
#X text 206 212 serialize result list.;
#X connect 0 0 6 0;
#X connect 2 0 3 0;
#X connect 5 0 4 0;
#X connect 6 0 8 0;
#X connect 7 0 9 0;
#X connect 8 0 7 0;
#X connect 8 1 13 1;
#X connect 9 0 11 0;
#X connect 10 0 13 0;
#X connect 11 0 10 0;
#X connect 11 1 12 1;
#X connect 12 0 15 0;
#X connect 13 0 14 0;
#X connect 14 0 12 0;
#X connect 16 0 0 0;
#X connect 16 1 2 0;
#X connect 16 2 5 0;
#X connect 17 0 16 0;


More information about the Pd-list mailing list