[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Does anyone have a better scm_string_hash ?
From: |
Marius Vollmer |
Subject: |
Re: Does anyone have a better scm_string_hash ? |
Date: |
Mon, 17 Nov 2003 16:42:35 +0100 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) |
Roland Orre <address@hidden> writes:
> /* replaced by Roland Orre address@hidden */
> #define hash_mask 0x00FFFFFF
> 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 */
> int i;
> /* originally h=0 was suggested. address@hidden */
> unsigned long h=177;
>
> for (i = len-1; i >= 0; i--)
> {
> /* h = (str[i] +i+ h*37) & hash_mask; */
> h = (str[i] + i + (h<<5) + (h<<2) + h) & hash_mask;
> }
> return h;
> } /* scm_string_hash */
g_string_hash from glib uses the same approach, but with 31 instead of
37 and with a h=0 seed:
/* 31 bit hash function */
guint
g_str_hash (gconstpointer key)
{
const char *p = key;
guint h = *p;
if (h)
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
return h;
}
So which one is it? :)
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?
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
- Re: cmod-play 1 available + modsup.h additions, (continued)
- Re: cmod-play 1 available + modsup.h additions, Marius Vollmer, 2003/11/14
- Does anyone have a better scm_string_hash ?, Roland Orre, 2003/11/14
- Re: Does anyone have a better scm_string_hash ?, Ludovic Courtès, 2003/11/14
- Re: Does anyone have a better scm_string_hash ?, Roland Orre, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?, Ludovic Courtès, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?,
Marius Vollmer <=
- Re: Does anyone have a better scm_string_hash ?, Marius Vollmer, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?, Marius Vollmer, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?, Allister MacLeod, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?, Marius Vollmer, 2003/11/17
- OT: x86 assembly timings/size (was Re: Does anyone have a better scm_string_hash ?), Allister MacLeod, 2003/11/17
- Re: OT: x86 assembly timings/size, Marius Vollmer, 2003/11/17
- Re: Does anyone have a better scm_string_hash ?, Ludovic Courtès, 2003/11/19
- Re: Does anyone have a better scm_string_hash ?, Marius Vollmer, 2003/11/19
Re: cmod-play 1 available + modsup.h additions, Thien-Thi Nguyen, 2003/11/14