00001 /* Description of GNU message catalog format: string hashing function.
00002 Copyright (C) 1995, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
00003
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.
00008
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 GNU General Public License for more details.
00013
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software Foundation,
00016 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
00017
00018 /* @@ end of prolog @@ */
00019
00020 #ifndef PARAMS
00021 # if __STDC__
00022 # define PARAMS(Args) Args
00023 # else
00024 # define PARAMS(Args) ()
00025 # endif
00026 #endif
00027
00028 /* We assume to have `unsigned long int' value with at least 32 bits. */
00029 #define HASHWORDBITS 32
00030
00031
00032 /* Defines the so called `hashpjw' function by P.J. Weinberger
00033 [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
00034 1986, 1987 Bell Telephone Laboratories, Inc.] */
00035 static unsigned long int hash_string PARAMS ((const char *__str_param));
00036
00037 static inline unsigned long int
00038 hash_string (str_param)
00039 const char *str_param;
00040 {
00041 unsigned long int hval, g;
00042 const char *str = str_param;
00043
00044 /* Compute the hash value for the given string. */
00045 hval = 0;
00046 while (*str != '\0')
00047 {
00048 hval <<= 4;
00049 hval += (unsigned long int) *str++;
00050 g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
00051 if (g != 0)
00052 {
00053 hval ^= g >> (HASHWORDBITS - 8);
00054 hval ^= g;
00055 }
00056 }
00057 return hval;
00058 }
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001