Sherlock, Ric wrote:
I was doing a case-insensitive lookup of firstname and lastname in a
2-column boxed table.
   fnames=: <;._1 ' John Dakota Wilson Diana Joan Roberto John John'
   lnames=: <;._1 ' Smith Jones Chan Wilson Saxon Angelo Smith Wilson'
   ]ppl=:500 $ fnames,.lnames

   p=: 'Joan';'Saxon'
   p2=:'JOAN';'saxon'
   ppl i. p
4
  (tolower each ppl) i. tolower each p2
4

However performance wasn't great, which I tracked it down to having to
run the verb tolower so many times. Below I've documented a solution to
this performance problem using inverted tables, but would be interested
in other possible ways of bypassing the performance hit caused by making
the lookup case-insensitive.

For longer lists, it is faster to apply tolower to the razed list, then box again, for example:

boxtolower=: 13 : '($y) $ <;._2 tolower ; y ,each {:a.'

   (tolower each ppl) i. tolower each p2
4

   (boxtolower ppl) i. boxtolower p2
4

   ts '(tolower each ppl) i. tolower each p2'
0.0133992 74752

   ts '(boxtolower ppl) i. boxtolower p2'
0.000680177 79936
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to