svn commit: r225161 - user/gabor/tre-integration/contrib/tre/lib

Gabor Kovesdan gabor at FreeBSD.org
Thu Aug 25 01:47:09 UTC 2011


Author: gabor
Date: Thu Aug 25 01:47:08 2011
New Revision: 225161
URL: http://svn.freebsd.org/changeset/base/225161

Log:
  - Eliminate duplicated code snippet
  - Improve portability by eliminating FreeBSD-related dependencies

Modified:
  user/gabor/tre-integration/contrib/tre/lib/hashtable.c

Modified: user/gabor/tre-integration/contrib/tre/lib/hashtable.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/hashtable.c	Thu Aug 25 01:00:54 2011	(r225160)
+++ user/gabor/tre-integration/contrib/tre/lib/hashtable.c	Thu Aug 25 01:47:08 2011	(r225161)
@@ -24,14 +24,29 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/hash.h>
-
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "hashtable.h"
 
+
+/*
+ * Return a 32-bit hash of the given buffer.  The init
+ * value should be 0, or the previous hash value to extend
+ * the previous hash.
+ */
+static uint32_t
+hash32_buf(const void *buf, size_t len, uint32_t hash)
+{
+  const unsigned char *p = buf;
+
+  while (len--)
+    hash = HASHSTEP(hash, *p++);
+
+  return hash;
+}
+
 /*
  * Initializes a hash table that can hold table_size number of entries,
  * each of which has a key of key_size bytes and a value of value_size
@@ -101,9 +116,6 @@ hashtable_put(hashtable *tbl, const void
 	return (HASH_UPDATED);
       }
 
-  while (tbl->entries[hash] != NULL)
-    hash = (hash >= tbl->table_size) ? 0 : hash + 1;
-
   tbl->entries[hash] = malloc(sizeof(hashtable_entry));
   if (tbl->entries[hash] == NULL)
     {


More information about the svn-src-user mailing list