emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: performance of converting alist to hash table


From: Dai Yuwen
Subject: Re: performance of converting alist to hash table
Date: Wed, 26 May 2004 13:29:36 +0000
User-agent: Mutt/1.4.2.1i

On Thu, May 20, 2004 at 08:27:30AM +0900, Kenichi Handa wrote:
> In article <address@hidden>, Dai Yuwen <address@hidden> writes:
> 
> > [1  <text/plain; us-ascii (7bit)>]
> > On Tue, May 18, 2004 at 09:42:20AM -0400, Stefan Monnier wrote:
> >>  > I use equal as the test function:
> >>  > (setq ta (make-hash-table :test 'equal :size 7000))
> >>  
> >>  > But I forgot to mention: the key of hash is a Chinese GB2312
> >>  > string. Does this slow down hashing?
> >>  
> >>  Can you post your complete code so we can reproduce the problem?
> >>  
> >>  
> > I attach the el file in the mail. There're GB2312 strings in the alist.
> 
> As keys are all one-char strings, I think a char-table is
> the most efficient method.
> 
> (put 'wubi-table 'char-table-extra-slots 0)
> (defvar wubi-table (make-char-table 'wubi-table nil))
> 
> (defun convert-alist-to-char-table (table w)
>   (mapc #'(lambda (e)
>           (aset table (aref (car e) 0) (cadr e)))
>       w))
> 
> ;;;; WuBi code for single Chinese char
> (convert-alist-to-char-table wubi-table '(
> [...]
> 
> You can access the value by (aref wubi-table
> ?_CHINESE_CHAR_), which is also very fast compared to
> gethash and assq.
> 
> If you also want a reverse mapping (i.e. WuBi to chinese
> char), you can use nested-alist.
> 
Thank you very much. I tried convert-alist-to-char-table. It runs suprisingly 
fast,
and (aref wubi-talbe ?_CHINESE_CHAR_) also runs much faster than gethash and
(cadr (assoc alist key)).

By the way, how do you know I'm writing a Wubi input method? Do you familiar 
with it?

best regards,
Dai yuwen
 
> ---
> Ken'ichi HANDA
> address@hidden

-- 
address@hidden
SDF Public Access UNIX System - http://sdf.lonestar.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]