bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add hash_pjw_s(), 4rd attempt


From: Jim Meyering
Subject: Re: Add hash_pjw_s(), 4rd attempt
Date: Tue, 02 Oct 2012 17:15:57 +0200

Nikos Mavrogiannopoulos wrote:
> On Mon, Oct 1, 2012 at 8:46 PM, Jim Meyering <address@hidden> wrote:
>
>>>  Any update on that? Do you plan to include it?
>> I went to deal with the mechanics of adding it and noticed a few details.
>> What do you think about hash_pjw_no_mod or hash_pjw_bare
>> as the function name?  They convey more meaning than the "_s" suffix.
>> Also, please make it look like other new-module commits.
>> I.e.,
>>   - list the module name in MODULES.html.sh
>>   - make the first line of the commit log be "new-module-name: new module"
>>   - add a ChangeLog entry
>
> The new patch should handle those.

Thanks.

That lacked a ChangeLog entry, added below.
I've marked this commit as Copyright-paperwork-exempt: yes
(aka "tiny change" in the ChangeLog file)
since it's nearly identical to the hash-pjw module.
If you contribute much more, you'll need to fill out FSF copyright
assignment paperwork.  Let me know if you'd like to start that
process already.  It can take a few weeks for people overseas.

I'll push the following in a few hours.


>From 85956be523901fb1ff734f5260e6f6441dd8088b Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <address@hidden>
Date: Thu, 27 Sep 2012 08:42:07 +0200
Subject: [PATCH] hash-pjw-bare: new module

* lib/hash-pjw-bare.c: New file, very much like hash-pjw.c.
* lib/hash-pjw-bare.h: Likewise.
* modules/hash-pjw-bare: New file.
* MODULES.html.sh (Misc): Add it.

Copyright-paperwork-exempt: yes
---
 ChangeLog             |  8 ++++++++
 MODULES.html.sh       |  1 +
 lib/hash-pjw-bare.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 lib/hash-pjw-bare.h   | 24 ++++++++++++++++++++++++
 modules/hash-pjw-bare | 22 ++++++++++++++++++++++
 5 files changed, 97 insertions(+)
 create mode 100644 lib/hash-pjw-bare.c
 create mode 100644 lib/hash-pjw-bare.h
 create mode 100644 modules/hash-pjw-bare

diff --git a/ChangeLog b/ChangeLog
index eb8e329..bab9b4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-10-02:  Nikos Mavrogiannopoulos  <address@hidden>  (tiny change)
+
+       hash-pjw-bare: new module
+       * lib/hash-pjw-bare.c: New file, very much like hash-pjw.c.
+       * lib/hash-pjw-bare.h: Likewise.
+       * modules/hash-pjw-bare: New file.
+       * MODULES.html.sh (Misc): Add it.
+
 2012-10-01  Ed Maste  <address@hidden>  (tiny change)

        select, poll tests: Make setsockopt invocation effective.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index baffef3..dc480ed 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2011,6 +2011,7 @@ func_all_modules ()
   func_module obstack-printf
   func_module obstack-printf-posix
   func_module hash-pjw
+  func_module hash-pjw-bare
   func_module hash
   func_module readline
   func_module readtokens
diff --git a/lib/hash-pjw-bare.c b/lib/hash-pjw-bare.c
new file mode 100644
index 0000000..d413daa
--- /dev/null
+++ b/lib/hash-pjw-bare.c
@@ -0,0 +1,42 @@
+/* hash-pjw-bare.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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include "hash-pjw-bare.h"
+
+#include <limits.h>
+
+#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_bare (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-bare.h b/lib/hash-pjw-bare.h
new file mode 100644
index 0000000..17ea755
--- /dev/null
+++ b/lib/hash-pjw-bare.h
@@ -0,0 +1,24 @@
+/* hash-pjw-bare.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 <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>
+
+/* 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_bare (const void *x, size_t n) _GL_ATTRIBUTE_PURE;
diff --git a/modules/hash-pjw-bare b/modules/hash-pjw-bare
new file mode 100644
index 0000000..4dc94e3
--- /dev/null
+++ b/modules/hash-pjw-bare
@@ -0,0 +1,22 @@
+Description:
+Compute a hash value for a buffer of known size.
+
+Files:
+lib/hash-pjw-bare.h
+lib/hash-pjw-bare.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += hash-pjw-bare.h hash-pjw-bare.c
+
+Include:
+"hash-pjw-bare.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+Jim Meyering
--
1.7.12.1.382.gb0576a6



reply via email to

[Prev in Thread] Current Thread [Next in Thread]