Logo Search packages:      
Sourcecode: belocs-locales-bin version File versions

strlen-hash.h

/* Implements hashing function for string with known length.
   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include <sys/types.h>

/* We assume to have `size_t' value with at least 32 bits.  */
#define HASHWORDBITS 32


/* Defines the so called `hashpjw' function by P.J. Weinberger
   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
   1986, 1987 Bell Telephone Laboratories, Inc.]  */
static size_t hash_string (const char *__str_param, size_t __len);

static inline size_t
hash_string (const char *str_param, size_t len)
{
  size_t hval, g;
  const char *end_str = str_param + len;

  /* Compute the hash value for the given string.  */
  hval = len;
  while (str_param != end_str)
    {
      hval <<= 4;
      hval += (size_t) *str_param++;
      g = hval & ((size_t) 0xf << (HASHWORDBITS - 4));
      if (g != 0)
      {
        hval ^= g >> (HASHWORDBITS - 8);
        hval ^= g;
      }
    }
  return hval;
}

Generated by  Doxygen 1.6.0   Back to index