1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 20:30:28 +02:00

(scm_string_hash): New hashing algorithm that takes the complete

string into account.
This commit is contained in:
Marius Vollmer 2003-11-17 16:56:48 +00:00
parent 64daa01285
commit b4d5926184

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1997, 2000, 2001 Free Software Foundation, Inc. /* Copyright (C) 1995,1996,1997, 2000, 2001, 2003 Free Software Foundation, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -37,22 +37,13 @@ extern double floor();
unsigned long unsigned long
scm_string_hash (const unsigned char *str, size_t len) scm_string_hash (const unsigned char *str, size_t len)
{ {
if (len > 5) /* from suggestion at: */
{ /* http://srfi.schemers.org/srfi-13/mail-archive/msg00112.html */
size_t i = 5;
unsigned long h = 264; unsigned long h = 0;
while (i--) while (len-- > 0)
h = (h << 8) + (unsigned) str[h % len]; h = *str++ + h*37;
return h; return h;
}
else
{
size_t i = len;
unsigned long h = 0;
while (i)
h = (h << 8) + (unsigned) str[--i];
return h;
}
} }