A very simple improvement of rpl3a will do, although efficiency is halved.
rpl3b=: 4 : 0
'x0 x1'=. x,"1 ~.,y
(x1 {~ x0 i. ]) y
)
Adopting Lams idea combines to the best of both worlds.
[lU=:|.Ul=:a.{~65 97+/ i.26 NB. lowerUpper and Upperlower
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ToLower =: (Ul&rpl3a) ` (Ul&rpl3b) @.(2~:3!:0)
ToUpper =: (lU& rpl3a) ` (lU& rpl3b) @.(2~:3!:0)
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens bill lam
> Verzonden: zaterdag 13 oktober 2007 4:08
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] Performance of case-insensitive lookup
>
> Chris Burke wrote:
> > The rpl3a method was essentially that used in J504, but replaced in J6
> > with a slower method that works with unicode, e.g.
> >
> > [A =: 3 2$'aBc' , (u:39321 28207), 'E'
> > aB
> > c香
> > 港E
> >
> > toupper A
> > AB
> > C香
> > 港E
> >
> > (((65,.97)+"0 _ i.26){a.)rpl3a A
> > |index error: rpl3a
> > | ((x1,a.){~(x0,a.)i.])y
> >
> > On the other hand, a 40x hit is quite a lot. It would be good to speed
> > up toupper and still work with unicode.
> >
>
> The toupper/tolower in script J602 does not use the special code for p {~
> q i. ]
> so that it did not fail for unicode. As Roger promised the bug on unicode
> will
> fixed in the next beta, toupper/tolower may become faster if it use the
> that
> special code. Alternatively providing two different branches after
> checking
> 3!:0 should make all ascii argument faster. eg.
>
> toupper=: [EMAIL PROTECTED](2~:3!:0)
>
> --
> regards,
> bill
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm