unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: Re: doco hash tables
Date: Thu, 28 Aug 2003 10:01:20 +1000	[thread overview]
Message-ID: <87u182myzz.fsf@zip.com.au> (raw)
In-Reply-To: 877k5dazob.fsf@zip.com.au

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


  reply	other threads:[~2003-08-28  0:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 23:02 doco hash tables Kevin Ryde
2003-08-17  0:35 ` Kevin Ryde
2003-08-28  0:01   ` Kevin Ryde [this message]
2003-09-15 13:48   ` Marius Vollmer
2003-10-09  0:16     ` Kevin Ryde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87u182myzz.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).