From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Marius Vollmer Newsgroups: gmane.lisp.guile.devel Subject: Re: Does anyone have a better scm_string_hash ? Date: Thu, 20 Nov 2003 18:29:21 +0100 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <8765hfhrta.fsf@zagadka.ping.de> References: <200311201548.hAKFmwM1021085@csserver.evansville.edu> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069349582 24691 80.91.224.253 (20 Nov 2003 17:33:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2003 17:33:02 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Nov 20 18:32:59 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AMsfr-0008VH-00 for ; Thu, 20 Nov 2003 18:32:59 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AMtcP-00046J-F0 for guile-devel@m.gmane.org; Thu, 20 Nov 2003 13:33:29 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AMtaN-0003SI-0U for guile-devel@gnu.org; Thu, 20 Nov 2003 13:31:23 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AMtZq-0003F4-J6 for guile-devel@gnu.org; Thu, 20 Nov 2003 13:31:21 -0500 Original-Received: from [195.253.8.218] (helo=mail.dokom.net) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AMtZq-0003Eh-1e for guile-devel@gnu.org; Thu, 20 Nov 2003 13:30:50 -0500 Original-Received: from dialin.speedway15.dip52.dokom.de ([195.253.15.52] helo=zagadka.ping.de) by mail.dokom.net with smtp (Exim 3.36 #3) id 1AMsfD-0008Gy-00 for guile-devel@gnu.org; Thu, 20 Nov 2003 18:32:19 +0100 Original-Received: (qmail 22889 invoked by uid 1000); 20 Nov 2003 17:29:21 -0000 Original-To: Stephen Compall In-Reply-To: <200311201548.hAKFmwM1021085@csserver.evansville.edu> (Stephen Compall's message of "Thu, 20 Nov 2003 15:48:58 GMT") User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3078 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3078 Stephen Compall writes: > /* This one comes from `recode', and performs a bit better than the above as > per a few experiments. It is inspired from a hashing routine found in the > very old Cyber `snoop', itself written in typical Greg Mansfield style. > (By the way, what happened to this excellent man? Is he still alive?) */ > > size_t > hash_string (const char *string, size_t n_buckets) > { > size_t value = 0; > > while (*string) > value = (value * 31 + (unsigned char) *string++) % n_buckets; > return value; > } This is essentially(?) the one used by glib. We use it with 37 instead of 31 and like glib, compute the module after the loop. unsigned long scm_string_hash (const unsigned char *str, size_t len) { /* from suggestion at: */ /* http://srfi.schemers.org/srfi-13/mail-archive/msg00112.html */ unsigned long h = 0; while (len-- > 0) h = *str++ + h*37; return h; } -- GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel