about summary refs log tree commit diff
path: root/locale/strlen-hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'locale/strlen-hash.h')
-rw-r--r--locale/strlen-hash.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/locale/strlen-hash.h b/locale/strlen-hash.h
new file mode 100644
index 0000000000..dba56dff21
--- /dev/null
+++ b/locale/strlen-hash.h
@@ -0,0 +1,51 @@
+/* strlen-hash - Implements hashing function for string with known length.
+Copyright (C) 1996 Free Software Foundation, Inc.
+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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  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;
+}