Date: Thu, 25 Aug 2011 01:47:08 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r225161 - user/gabor/tre-integration/contrib/tre/lib Message-ID: <201108250147.p7P1l8Fj079279@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108250147.p7P1l8Fj079279>