guile-devel
[Top][All Lists]
Advanced

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

Re: doco hash tables


From: Kevin Ryde
Subject: Re: doco hash tables
Date: Thu, 28 Aug 2003 10:01:20 +1000
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux)

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::).




reply via email to

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