OK here are some more comprehensive comparisons of the Looping algorithm and
the best of the Jish ones. (I've modified both to handle empty tables.)
The main parameters of interest are the Length of the boxed list, and the Size
of the tables so:
]'Length Size'=: |:>,{500 40 5;300 100 20
500 500 500 40 40 40 5 5 5
300 100 20 300 100 20 300 100 20
>From the table below it seems that as the Length increases the looping
>solution is slightly slower than the Jish solution as long as the table Size
>remains small. If the table Size is medium to large then the superiority of
>the looping solution actually increases. I imagine this is related to the
>amount of RAM available and that the Jish solution takes a long time for big
>tables because it has to use the Page file??
(<"1 Length,.Size),.Length test each Size
+-------+------------------------+
|500 300|0.985666614053 67002944|
| | 2.9590480075 503416896|
+-------+------------------------+
|500 100|0.112628280969 7162048 |
| |0.305418775291 53582528 |
+-------+------------------------+
|500 20 |0.0177151006622 328128 |
| |0.0114430046277 2184896 |
+-------+------------------------+
|40 300 |0.0888279096924 7916736|
| | 0.221431704309 43437632|
+-------+------------------------+
|40 100 |0.00885342969567 874240|
| | 0.0211174185546 4847808|
+-------+------------------------+
|40 20 |0.000804431848182 39168|
| |0.000759314382135 196352|
+-------+------------------------+
|5 300 |0.0130150619702 2651456 |
| |0.0254019016383 6089344 |
+-------+------------------------+
|5 100 | 0.0014076509724 384192 |
| |0.00164650814559 862464 |
+-------+------------------------+
|5 20 |0.000110628585477 22720 |
| |0.000116844459282 34240 |
+-------+------------------------+
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
rndidx=: 3 : 0
nidx=.>.0.75* */$y
~.(nidx,2)?.@:$ $y
)
rndcnts=: # ?. */@:$
amendloop=: 4 : 0
n=.''
'cnts idx'=. x
for_cnt. cnts do.
n=.n,< (>cnt) (<"1^:(0:<#) cnt_index{::idx) } cnt_index{::y
end.
)
box_amendb =: 4 : '<(>1{x) (>0{x) } >y'
test=: 4 : 0
m=. x (] ?.@:$~ 2 ,~ [) y
m=. 0 (I. 0= */"1 m)}m
m=. m <@$"1 ]0
idx=. rndidx each m NB. Create random scattered indexes
contents=. rndcnts each idx NB. Create contents to amend
loop=. '(contents;<idx) amendloop m'
rs2=. '((<"1^:(0:<#) each idx),.contents) box_amendb"1 0 m'
LP=. ts loop
RS=. ts rs2
LP,:RS
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm