There is a faster, shorter, and easier to understand alternative: <: #/.~ B,A that is, preface with the universe of interest, calculate the counts, and decrement the counts due to the universe being tacked on.
datai=: 3 : 0 NB. integer test data N=: y B=: 100+ i.N*10 A1=: 100+ ?.2 8$&(N&*)10 A2=: ,A1 i.0 0 ) datas=: 3 : 0 NB. boxed strings test data N=: y B=: <@":"0] 100+ i.N*10 A1=: <@":"0] 100+ ?.2 8$&(N&*)10 A2=: ,A1 i.0 0 ) datai 100 NB. integers ts '((B e. ~.) #^:_1 #/.~)@/:~"1 A1' 0.0152793 1.07571e6 ts '<: #/.~"1 B,"1 A1' 0.0121803 4.19603e6 ts '((B e. ~.) #^:_1 #/.~)@/:~"1 A2' 0.00672655 1.06342e6 ts '<: #/.~"1 B,"1 A2' 0.00321549 1.0585e6 datas 50 NB. boxed strings ts '((B e. ~.) #^:_1 #/.~)@/:~"1 A1' 0.0653997 280064 ts '<: #/.~"1 B,"1 A1' 0.0190351 1.0503e6 ts '((B e. ~.) #^:_1 #/.~)@/:~"1 A2' 0.154324 1.47712e6 ts '<: #/.~"1 B,"1 A2' 0.0174768 1.05024e6 Regarding the comment: > Remarkably strings are 10-100 times slower > than integers, but report the same time for > almost all the tests. The remarkable thing is that integers are 10-100 times faster than boxed strings. Integers have properties that are absent from boxed strings (and other data), and the special properties are being exploited for more efficient computation. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
