Back to Evolution Project page


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Header Files   Sources   Compound Members   File Members  

hash-string.h

00001 /* Implements a string hashing function.
00002    Copyright (C) 1995, 1997 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 Library General Public
00015    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00016    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.  */
00018 
00019 /* @@ end of prolog @@ */
00020 
00021 #ifndef PARAMS
00022 # if __STDC__
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 at Mon Nov 6 22:47:04 2000 for TheGameofEvolution by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999