Small-Range Index   <<   >>

 
x i. y  or  x ⍳ y when x and y are small-range
cf. pigeonhole principle

R=1+max-min;                    // range of x and y
t=t0=getspace(R*sizeof(I4));    // allocate table of size R (the pigeonholes)
DO(R, *t++=xn;);                // initialize table to xn (“not found”)
t=t0-min;                       // table with offset
x+=j=xn;
DO(xn, t[*--x]=--j;);           // process x in reverse order
DO(yn, *z++=t[*y++];);


z=. (y-min) { (i.-xn) (|.x-min)} R$xn

z←t[y-min] ⊣ t[⌽x-min]←⌽⍳xn ⊣ t←R⍴xn