From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: doco hash tables Date: Thu, 28 Aug 2003 10:01:20 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87u182myzz.fsf@zip.com.au> References: <87oezb1uut.fsf@zip.com.au> <877k5dazob.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1062032111 31622 80.91.224.253 (28 Aug 2003 00:55:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 28 Aug 2003 00:55:11 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Aug 28 02:55:10 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 19sB49-0005mH-00 for ; Thu, 28 Aug 2003 02:55:09 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19sB3F-0003Sz-9R for guile-devel@m.gmane.org; Wed, 27 Aug 2003 20:54:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19sAPD-0001jS-CB for guile-devel@gnu.org; Wed, 27 Aug 2003 20:12:51 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19sAKm-0007du-7f for guile-devel@gnu.org; Wed, 27 Aug 2003 20:08:16 -0400 Original-Received: from [61.8.0.36] (helo=snoopy.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.22) id 19sAEP-0005bz-J7 for guile-devel@gnu.org; Wed, 27 Aug 2003 20:01:41 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h7S01Z0J012161 for ; Thu, 28 Aug 2003 10:01:39 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h7S01Zkv027467 for ; Thu, 28 Aug 2003 10:01:35 +1000 (EST) Original-Received: from localhost (ppp99.dyn228.pacific.net.au [203.143.228.99]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h7S01Wvj025727 for ; Thu, 28 Aug 2003 10:01:33 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19sAE6-0000ef-00; Thu, 28 Aug 2003 10:01:22 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) 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:2726 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2726 A bit more for the hash functions section, * scheme-compound.texi (Hash Table Reference): Add hashx case insensitive string example, add cross references to symbol-hash, string-hash, and char-set-hash. For the `hashx-' "extended" routines, an application supplies a HASH function producing an integer index like `hashq' etc below, and an ASSOC alist search function like `assq' etc (*note Retrieving Alist Entries::). Here's an example of such functions implementing case-insensitive hashing of string keys, (use-modules (srfi srfi-1) (srfi srfi-13)) (define (my-hash str size) (remainder (string-hash-ci str) size)) (define (my-assoc str alist) (find (lambda (pair) (string-ci=? str (car pair))) alist)) (define my-table (make-hash-table)) (hashx-set! my-hash my-assoc my-table "foo" 123) (hashx-ref my-hash my-assoc my-table "FOO") => 123 In a `hashx-' HASH function the aim is to spread keys across the vector, so bucket lists don't become long, but the actual values are arbitrary (so long as they're in the range 0 to SIZE-1). Helpful functions for forming a hash value include `symbol-hash' (*note Symbol Keys::), `string-hash' (*note SRFI-13 Comparison::), and `char-set-hash' (*note SRFI-14 Predicates/Comparison::). _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel