Blame intl/hash-string.h

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