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