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