Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

hash-string.h

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 it
00005    under the terms of the GNU Library General Public License as published
00006    by 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 GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017    USA.  */
00018 
00019 /* @@ end of prolog @@ */
00020 
00021 #ifndef PARAMS
00022 # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
00023 #  define PARAMS(Args) Args
00024 # else
00025 #  define PARAMS(Args) ()
00026 # endif
00027 #endif
00028 
00029 /* We assume to have `unsigned long int' value with at least 32 bits.  */
00030 #define HASHWORDBITS 32
00031 
00032 
00033 /* Defines the so called `hashpjw' function by P.J. Weinberger
00034    [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
00035    1986, 1987 Bell Telephone Laboratories, Inc.]  */
00036 static unsigned long int hash_string PARAMS ((const char *__str_param));
00037 
00038 static inline unsigned long int
00039 hash_string (str_param)
00040      const char *str_param;
00041 {
00042   unsigned long int hval, g;
00043   const char *str = str_param;
00044 
00045   /* Compute the hash value for the given string.  */
00046   hval = 0;
00047   while (*str != '\0')
00048     {
00049       hval <<= 4;
00050       hval += (unsigned long int) *str++;
00051       g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
00052       if (g != 0)
00053         {
00054           hval ^= g >> (HASHWORDBITS - 8);
00055           hval ^= g;
00056         }
00057     }
00058   return hval;
00059 }

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18