|
Packit Service |
a721b1 |
/* Implements a string hashing function.
|
|
Packit Service |
a721b1 |
Copyright (C) 1995, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
|
|
Packit Service |
a721b1 |
This file is part of the GNU C Library.
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
a721b1 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
a721b1 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
a721b1 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
a721b1 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a721b1 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
a721b1 |
Lesser General Public License for more details.
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
a721b1 |
License along with the GNU C Library; if not, write to the Free
|
|
Packit Service |
a721b1 |
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
a721b1 |
Boston, MA 02110-1301, USA. */
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
a721b1 |
# include <config.h>
|
|
Packit Service |
a721b1 |
#endif
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
/* Specification. */
|
|
Packit Service |
a721b1 |
#include "hash-string.h"
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
/* Defines the so called `hashpjw' function by P.J. Weinberger
|
|
Packit Service |
a721b1 |
[see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
|
|
Packit Service |
a721b1 |
1986, 1987 Bell Telephone Laboratories, Inc.] */
|
|
Packit Service |
a721b1 |
unsigned long int
|
|
Packit Service |
a721b1 |
__hash_string (const char *str_param)
|
|
Packit Service |
a721b1 |
{
|
|
Packit Service |
a721b1 |
unsigned long int hval, g;
|
|
Packit Service |
a721b1 |
const char *str = str_param;
|
|
Packit Service |
a721b1 |
|
|
Packit Service |
a721b1 |
/* Compute the hash value for the given string. */
|
|
Packit Service |
a721b1 |
hval = 0;
|
|
Packit Service |
a721b1 |
while (*str != '\0')
|
|
Packit Service |
a721b1 |
{
|
|
Packit Service |
a721b1 |
hval <<= 4;
|
|
Packit Service |
a721b1 |
hval += (unsigned char) *str++;
|
|
Packit Service |
a721b1 |
g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
|
|
Packit Service |
a721b1 |
if (g != 0)
|
|
Packit Service |
a721b1 |
{
|
|
Packit Service |
a721b1 |
hval ^= g >> (HASHWORDBITS - 8);
|
|
Packit Service |
a721b1 |
hval ^= g;
|
|
Packit Service |
a721b1 |
}
|
|
Packit Service |
a721b1 |
}
|
|
Packit Service |
a721b1 |
return hval;
|
|
Packit Service |
a721b1 |
}
|