>From 14a0d1ac40de4fcd16dff605a0fdf86a8227520f Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos
Date: Thu, 27 Sep 2012 08:42:07 +0200
Subject: [PATCH] Added hash-pjw-s.
---
lib/hash-pjw-s.c | 42 ++++++++++++++++++++++++++++++++++++++++++
lib/hash-pjw-s.h | 24 ++++++++++++++++++++++++
modules/hash-pjw-s | 22 ++++++++++++++++++++++
3 files changed, 88 insertions(+)
create mode 100644 lib/hash-pjw-s.c
create mode 100644 lib/hash-pjw-s.h
create mode 100644 modules/hash-pjw-s
diff --git a/lib/hash-pjw-s.c b/lib/hash-pjw-s.c
new file mode 100644
index 0000000..3765e35
--- /dev/null
+++ b/lib/hash-pjw-s.c
@@ -0,0 +1,42 @@
+/* hash-pjw-s.c -- compute a hash value from a provided buffer.
+
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ This program 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 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program. If not, see . */
+
+#include
+
+#include "hash-pjw-s.h"
+
+#include
+
+#define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
+
+/* Return a hash of the N bytes of X using the method described by
+ Bruno Haible in http://www.haible.de/bruno/hashfunc.html.
+ Note that while many hash functions reduce their result via modulo
+ to a 0..table_size-1 range, this function does not do that. */
+
+size_t
+hash_pjw_s (const void *x, size_t n)
+{
+ const unsigned char *s = x;
+ size_t h = 0;
+ unsigned i;
+
+ for (i = 0; i < n; i++)
+ h = s[i] + ((h << 9) | (h >> (SIZE_BITS - 9)));
+
+ return h;
+}
diff --git a/lib/hash-pjw-s.h b/lib/hash-pjw-s.h
new file mode 100644
index 0000000..cf61f8d
--- /dev/null
+++ b/lib/hash-pjw-s.h
@@ -0,0 +1,24 @@
+/* hash-pjw-s.h -- declaration for a simple hash function
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ This program 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 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 this program. If not, see . */
+
+#include
+
+/* Compute a hash code for a buffer starting at X and of size N,
+ and return the hash code. Note that unlike hash_pjw(), it does not
+ return it modulo a table size.
+ The result is platform dependent: it depends on the size of the 'size_t'
+ type and on the signedness of the 'char' type. */
+extern size_t hash_pjw_s (const void *x, size_t n) _GL_ATTRIBUTE_PURE;
diff --git a/modules/hash-pjw-s b/modules/hash-pjw-s
new file mode 100644
index 0000000..d8735ca
--- /dev/null
+++ b/modules/hash-pjw-s
@@ -0,0 +1,22 @@
+Description:
+Compute a hash value for a buffer of known size.
+
+Files:
+lib/hash-pjw-s.h
+lib/hash-pjw-s.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += hash-pjw-s.h hash-pjw-s.c
+
+Include:
+"hash-pjw-s.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+Jim Meyering
--
1.7.10.4