mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-25 04:40:19 +02:00
(scm_string_hash): New hashing algorithm that takes the complete
string into account.
This commit is contained in:
parent
64daa01285
commit
b4d5926184
1 changed files with 8 additions and 17 deletions
|
@ -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;
|
|
||||||
while (i--)
|
|
||||||
h = (h << 8) + (unsigned) str[h % len];
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size_t i = len;
|
|
||||||
unsigned long h = 0;
|
unsigned long h = 0;
|
||||||
while (i)
|
while (len-- > 0)
|
||||||
h = (h << 8) + (unsigned) str[--i];
|
h = *str++ + h*37;
|
||||||
return h;
|
return h;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue