unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Marius Vollmer <mvo@zagadka.de>
Cc: guile-user@gnu.org
Subject: Re: Does anyone have a better scm_string_hash ?
Date: Mon, 17 Nov 2003 17:02:43 +0100	[thread overview]
Message-ID: <87u153q8yk.fsf@zagadka.ping.de> (raw)
In-Reply-To: <874qx3rogk.fsf@zagadka.ping.de> (Marius Vollmer's message of "Mon, 17 Nov 2003 16:42:35 +0100")

Marius Vollmer <mvo@zagadka.de> writes:

> Both should be much better than the one we have right now and I'm
> going to install the one from Roland without the hash_mask.

Ok, I have installed the following hash function into 1.7.  As a nice
side effect, guile seems to start a bit faster now.  (Although the new
function does more work than the old.  Talk about being too clever.)

    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[i] + h*37) % 2^bits_per_long; */
          h = *str++ + (h<<5) + (h<<2) + h;
        }
      return h;
    }

I removed 'i' from the calculation since neither the glib function nor
the one from Java uses it and I'm wary of heuristical magic when it
comes to random number generation and hash functions.  Permutations of
the input will still lead to different hash values since, for example
str[0]+str[1]*37 is different from str[1]+str[0]*37.

Just for kicks, I'm now going to see what kind of code GCC generates
for h*37 as compared to (h<<5) + (h<<2) + 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


       reply	other threads:[~2003-11-17 16:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1AKPRR-00036l-00@surf.glug.org>
     [not found] ` <8765hnf308.fsf@zagadka.ping.de>
     [not found]   ` <1068823738.13123.54.camel@localhost>
     [not found]     ` <20031114155148.GI16650@powergnu.laas.fr>
     [not found]       ` <1069058032.1638.21.camel@localhost>
     [not found]         ` <874qx3rogk.fsf@zagadka.ping.de>
2003-11-17 16:02           ` Marius Vollmer [this message]
2003-11-17 16:29             ` Does anyone have a better scm_string_hash ? Marius Vollmer
2003-11-18 20:15               ` Kevin Ryde
2003-11-19  9:04             ` Ludovic Courtès
2003-11-19 15:02               ` Marius Vollmer
2003-11-20 15:48 Stephen Compall
2003-11-20 17:29 ` Marius Vollmer
  -- strict thread matches above, loose matches on Subject: below --
2003-11-14 18:11 Roland Orre
2003-11-14 20:09 ` Andreas Rottmann

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=87u153q8yk.fsf@zagadka.ping.de \
    --to=mvo@zagadka.de \
    --cc=guile-user@gnu.org \
    /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).