Blame intl/hash-string.h

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