1*2a6b7db3Sskrll /* Description of GNU message catalog format: string hashing function.
2*2a6b7db3Sskrll    Copyright (C) 1995, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
3*2a6b7db3Sskrll 
4*2a6b7db3Sskrll    This program is free software; you can redistribute it and/or modify it
5*2a6b7db3Sskrll    under the terms of the GNU Library General Public License as published
6*2a6b7db3Sskrll    by the Free Software Foundation; either version 2, or (at your option)
7*2a6b7db3Sskrll    any later version.
8*2a6b7db3Sskrll 
9*2a6b7db3Sskrll    This program is distributed in the hope that it will be useful,
10*2a6b7db3Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*2a6b7db3Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*2a6b7db3Sskrll    Library General Public License for more details.
13*2a6b7db3Sskrll 
14*2a6b7db3Sskrll    You should have received a copy of the GNU Library General Public
15*2a6b7db3Sskrll    License along with this program; if not, write to the Free Software
16*2a6b7db3Sskrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
17*2a6b7db3Sskrll    USA.  */
18*2a6b7db3Sskrll 
19*2a6b7db3Sskrll /* @@ end of prolog @@ */
20*2a6b7db3Sskrll 
21*2a6b7db3Sskrll #ifndef PARAMS
22*2a6b7db3Sskrll # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
23*2a6b7db3Sskrll #  define PARAMS(Args) Args
24*2a6b7db3Sskrll # else
25*2a6b7db3Sskrll #  define PARAMS(Args) ()
26*2a6b7db3Sskrll # endif
27*2a6b7db3Sskrll #endif
28*2a6b7db3Sskrll 
29*2a6b7db3Sskrll /* We assume to have `unsigned long int' value with at least 32 bits.  */
30*2a6b7db3Sskrll #define HASHWORDBITS 32
31*2a6b7db3Sskrll 
32*2a6b7db3Sskrll 
33*2a6b7db3Sskrll /* Defines the so called `hashpjw' function by P.J. Weinberger
34*2a6b7db3Sskrll    [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
35*2a6b7db3Sskrll    1986, 1987 Bell Telephone Laboratories, Inc.]  */
36*2a6b7db3Sskrll static unsigned long int hash_string PARAMS ((const char *__str_param));
37*2a6b7db3Sskrll 
38*2a6b7db3Sskrll static inline unsigned long int
hash_string(str_param)39*2a6b7db3Sskrll hash_string (str_param)
40*2a6b7db3Sskrll      const char *str_param;
41*2a6b7db3Sskrll {
42*2a6b7db3Sskrll   unsigned long int hval, g;
43*2a6b7db3Sskrll   const char *str = str_param;
44*2a6b7db3Sskrll 
45*2a6b7db3Sskrll   /* Compute the hash value for the given string.  */
46*2a6b7db3Sskrll   hval = 0;
47*2a6b7db3Sskrll   while (*str != '\0')
48*2a6b7db3Sskrll     {
49*2a6b7db3Sskrll       hval <<= 4;
50*2a6b7db3Sskrll       hval += (unsigned long int) *str++;
51*2a6b7db3Sskrll       g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
52*2a6b7db3Sskrll       if (g != 0)
53*2a6b7db3Sskrll 	{
54*2a6b7db3Sskrll 	  hval ^= g >> (HASHWORDBITS - 8);
55*2a6b7db3Sskrll 	  hval ^= g;
56*2a6b7db3Sskrll 	}
57*2a6b7db3Sskrll     }
58*2a6b7db3Sskrll   return hval;
59*2a6b7db3Sskrll }
60