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: Kenichi Handa
Subject: Re: performance of converting alist to hash table
Date: Thu, 20 May 2004 08:27:30 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.3 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

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.

---
Ken'ichi HANDA
address@hidden




reply via email to

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