From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dai Yuwen Newsgroups: gmane.emacs.devel Subject: Re: performance of converting alist to hash table Date: Wed, 26 May 2004 13:29:36 +0000 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20040526132936.GA22985@SDF.LONESTAR.ORG> References: <20040516095522.GA1625@SDF.LONESTAR.ORG> <4n3c5zj6eq.fsf@lifelogs.com> <20040517233743.GA11854@fencepost> <20040518115030.GA21952@SDF.LONESTAR.ORG> <20040519115903.GA2149@SDF.LONESTAR.ORG> <200405192327.IAA14876@etlken.m17n.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085582422 9386 80.91.224.253 (26 May 2004 14:40:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 26 May 2004 14:40:22 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed May 26 16:40:11 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BSzW8-0004JG-00 for ; Wed, 26 May 2004 16:36:28 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BSzW7-0007GR-00 for ; Wed, 26 May 2004 16:36:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BSydF-0002SS-Dp for emacs-devel@quimby.gnus.org; Wed, 26 May 2004 09:39:45 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BSycm-0002RY-5T for emacs-devel@gnu.org; Wed, 26 May 2004 09:39:16 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BSycE-0002Na-BB for emacs-devel@gnu.org; Wed, 26 May 2004 09:39:14 -0400 Original-Received: from [192.94.73.20] (helo=sdf.lonestar.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BSyap-0002G2-WE for emacs-devel@gnu.org; Wed, 26 May 2004 09:37:18 -0400 Original-Received: from sdf.lonestar.org (IDENT:daiyuwen@sdf.lonestar.org [192.94.73.1]) by sdf.lonestar.org (8.12.10/8.12.10) with ESMTP id i4QDTdgA003967; Wed, 26 May 2004 13:29:40 GMT Original-Received: (from daiyuwen@localhost) by sdf.lonestar.org (8.12.10/8.12.8/Submit) id i4QDTaWl011976; Wed, 26 May 2004 13:29:36 GMT Original-To: Kenichi Handa Content-Disposition: inline In-Reply-To: <200405192327.IAA14876@etlken.m17n.org> User-Agent: Mutt/1.4.2.1i X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:23959 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:23959 On Thu, May 20, 2004 at 08:27:30AM +0900, Kenichi Handa wrote: > In article <20040519115903.GA2149@SDF.LONESTAR.ORG>, Dai Yuwen writes: > > > [1 ] > > 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 > handa@m17n.org -- daiyuwen@freeshell.org SDF Public Access UNIX System - http://sdf.lonestar.org