Exercise 9 Index   <<   >>


 

Consider the following model for computing x⍳y for small-range x and y . (Also at http://www.jsoftware.com/papers/APLHashingModel.htm .) Write xiySR , a non-looping version of it.


 z←x xiySRloop y;⎕io;i;max;min;n;t
⍝ small-range version of x⍳y; written for easy translation into C
 ⎕io←0
 n←≢x
 min←⌊/x,y
 max←⌈/x,y
 t←(1+max-min)⍴n                              ⍝ table of indices
 z←(≢y)⍴0                                     ⍝ eventual result
 :For i :In ⌽⍳n ⋄ t[x[i]-min]←i    ⋄ :EndFor  ⍝ populate table
 :For i :In ⍳≢y ⋄ z[i]←t[y[i]-min] ⋄ :EndFor  ⍝ read index for each y











 z←x xiySR y;⎕io;max;min;n;t
⍝ small-range version of x⍳y
 ⎕io←0
 n←≢x
 min←⌊/x,y
 max←⌈/x,y
 t←(1+max-min)⍴n  ⍝ table of indices
 t[⌽x-min]←⌽⍳n    ⍝ populate table
 z←t[y-min]       ⍝ read index for each y