Blame intl/hash-string.h

Packit bbfece
/* Description of GNU message catalog format: string hashing function.
Packit bbfece
   Copyright (C) 1995, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
Packit bbfece
Packit bbfece
   This program is free software; you can redistribute it and/or modify it
Packit bbfece
   under the terms of the GNU Library General Public License as published
Packit bbfece
   by the Free Software Foundation; either version 2, or (at your option)
Packit bbfece
   any later version.
Packit bbfece
Packit bbfece
   This program is distributed in the hope that it will be useful,
Packit bbfece
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bbfece
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit bbfece
   Library General Public License for more details.
Packit bbfece
Packit bbfece
   You should have received a copy of the GNU Library General Public
Packit bbfece
   License along with this program; if not, write to the Free Software
Packit bbfece
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
Packit bbfece
   USA.  */
Packit bbfece
Packit bbfece
/* @@ end of prolog @@ */
Packit bbfece
Packit bbfece
#ifndef PARAMS
Packit bbfece
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
Packit bbfece
#  define PARAMS(Args) Args
Packit bbfece
# else
Packit bbfece
#  define PARAMS(Args) ()
Packit bbfece
# endif
Packit bbfece
#endif
Packit bbfece
Packit bbfece
/* We assume to have `unsigned long int' value with at least 32 bits.  */
Packit bbfece
#define HASHWORDBITS 32
Packit bbfece
Packit bbfece
Packit bbfece
/* Defines the so called `hashpjw' function by P.J. Weinberger
Packit bbfece
   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
Packit bbfece
   1986, 1987 Bell Telephone Laboratories, Inc.]  */
Packit bbfece
static unsigned long int hash_string PARAMS ((const char *__str_param));
Packit bbfece
Packit bbfece
static inline unsigned long int
Packit bbfece
hash_string (str_param)
Packit bbfece
     const char *str_param;
Packit bbfece
{
Packit bbfece
  unsigned long int hval, g;
Packit bbfece
  const char *str = str_param;
Packit bbfece
Packit bbfece
  /* Compute the hash value for the given string.  */
Packit bbfece
  hval = 0;
Packit bbfece
  while (*str != '\0')
Packit bbfece
    {
Packit bbfece
      hval <<= 4;
Packit bbfece
      hval += (unsigned long int) *str++;
Packit bbfece
      g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
Packit bbfece
      if (g != 0)
Packit bbfece
	{
Packit bbfece
	  hval ^= g >> (HASHWORDBITS - 8);
Packit bbfece
	  hval ^= g;
Packit bbfece
	}
Packit bbfece
    }
Packit bbfece
  return hval;
Packit bbfece
}