1*3fb98d4aSespie /* Description of GNU message catalog format: string hashing function. 2*3fb98d4aSespie Copyright (C) 1995, 1997, 1998, 2000, 2001 Free Software Foundation, Inc. 3840175f0Skstailey 4*3fb98d4aSespie This program is free software; you can redistribute it and/or modify it 5*3fb98d4aSespie under the terms of the GNU Library General Public License as published 6*3fb98d4aSespie by the Free Software Foundation; either version 2, or (at your option) 7840175f0Skstailey any later version. 8840175f0Skstailey 9840175f0Skstailey This program is distributed in the hope that it will be useful, 10840175f0Skstailey but WITHOUT ANY WARRANTY; without even the implied warranty of 11*3fb98d4aSespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12*3fb98d4aSespie Library General Public License for more details. 13840175f0Skstailey 1428ea187bSespie You should have received a copy of the GNU Library General Public 15*3fb98d4aSespie License along with this program; if not, write to the Free Software 16*3fb98d4aSespie Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 17*3fb98d4aSespie USA. */ 18840175f0Skstailey 19840175f0Skstailey /* @@ end of prolog @@ */ 20840175f0Skstailey 21840175f0Skstailey #ifndef PARAMS 22*3fb98d4aSespie # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES 23840175f0Skstailey # define PARAMS(Args) Args 24840175f0Skstailey # else 25840175f0Skstailey # define PARAMS(Args) () 26840175f0Skstailey # endif 27840175f0Skstailey #endif 28840175f0Skstailey 29840175f0Skstailey /* We assume to have `unsigned long int' value with at least 32 bits. */ 30840175f0Skstailey #define HASHWORDBITS 32 31840175f0Skstailey 32840175f0Skstailey 33840175f0Skstailey /* Defines the so called `hashpjw' function by P.J. Weinberger 34840175f0Skstailey [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 35840175f0Skstailey 1986, 1987 Bell Telephone Laboratories, Inc.] */ 36*3fb98d4aSespie static unsigned long int hash_string PARAMS ((const char *__str_param)); 37840175f0Skstailey 38*3fb98d4aSespie static inline unsigned long int 39840175f0Skstailey hash_string (str_param) 40840175f0Skstailey const char *str_param; 41840175f0Skstailey { 42840175f0Skstailey unsigned long int hval, g; 43840175f0Skstailey const char *str = str_param; 44840175f0Skstailey 45840175f0Skstailey /* Compute the hash value for the given string. */ 46840175f0Skstailey hval = 0; 47840175f0Skstailey while (*str != '\0') 48840175f0Skstailey { 49840175f0Skstailey hval <<= 4; 50*3fb98d4aSespie hval += (unsigned long int) *str++; 51*3fb98d4aSespie g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); 52840175f0Skstailey if (g != 0) 53840175f0Skstailey { 54840175f0Skstailey hval ^= g >> (HASHWORDBITS - 8); 55840175f0Skstailey hval ^= g; 56840175f0Skstailey } 57840175f0Skstailey } 58840175f0Skstailey return hval; 59840175f0Skstailey } 60