]> git.ozlabs.org Git - ccan/commitdiff
tdb2: make jenkins_hash function non-static, rename to tdb_jenkins_hash.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:05 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:05 +0000 (15:31 +0930)
We're going to need access to it from tdb1_open, so expose it now.
It's better in hash.c anyway.

ccan/tdb2/hash.c
ccan/tdb2/open.c
ccan/tdb2/private.h
ccan/tdb2/test/failtest_helper.h
ccan/tdb2/test/run-90-get-set-attributes.c

index 1359cfecd66dc6280e3314e78fd2e7e5ea91c8bd..56c5086e742552480a23e81a8e2a7baafe583d73 100644 (file)
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include "private.h"
+#include <ccan/hash/hash.h>
 #include <assert.h>
 
+/* Default hash function. */
+uint64_t tdb_jenkins_hash(const void *key, size_t length, uint64_t seed,
+                         void *unused)
+{
+       uint64_t ret;
+       /* hash64_stable assumes lower bits are more important; they are a
+        * slightly better hash.  We use the upper bits first, so swap them. */
+       ret = hash64_stable((const unsigned char *)key, length, seed);
+       return (ret >> 32) | (ret << 32);
+}
+
 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
 {
        return tdb->hash_fn(ptr, len, tdb->hash_seed, tdb->hash_data);
index e4551c8405e8ced1c3e72fa11ab1079b405a04d4..49804acfba427236382eb5e76d9790e05833eea7 100644 (file)
@@ -16,7 +16,6 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include "private.h"
-#include <ccan/hash/hash.h>
 #include <assert.h>
 
 /* all tdbs, to detect double-opens (fcntl file don't nest!) */
@@ -242,16 +241,6 @@ enum TDB_ERROR tdb_set_attribute(struct tdb_context *tdb,
        return TDB_SUCCESS;
 }
 
-static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
-                            void *unused)
-{
-       uint64_t ret;
-       /* hash64_stable assumes lower bits are more important; they are a
-        * slightly better hash.  We use the upper bits first, so swap them. */
-       ret = hash64_stable((const unsigned char *)key, length, seed);
-       return (ret >> 32) | (ret << 32);
-}
-
 enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb,
                                 union tdb_attribute *attr)
 {
@@ -371,7 +360,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        tdb->openhook = NULL;
        tdb->lock_fn = tdb_fcntl_lock;
        tdb->unlock_fn = tdb_fcntl_unlock;
-       tdb->hash_fn = jenkins_hash;
+       tdb->hash_fn = tdb_jenkins_hash;
        memset(&tdb->stats, 0, sizeof(tdb->stats));
        tdb->stats.base.attr = TDB_ATTRIBUTE_STATS;
        tdb->stats.size = sizeof(tdb->stats);
index 600d3b5f181fa1bf29a3e1b35ee199ce6e069249..4bce11a1c539ea8e39bb09c6179d495bf669e342 100644 (file)
@@ -338,6 +338,9 @@ struct tdb_methods {
   internal prototypes
 */
 /* hash.c: */
+uint64_t tdb_jenkins_hash(const void *key, size_t length, uint64_t seed,
+                         void *unused);
+
 tdb_bool_err first_in_hash(struct tdb_context *tdb,
                           struct traverse_info *tinfo,
                           TDB_DATA *kbuf, size_t *dlen);
index 73cd1aeb1ece516092d1bcfd9cea18040862b51f..a585dc2b65f8d5380f5e2a84d4f9e12d4f14a24b 100644 (file)
@@ -4,9 +4,9 @@
 #include <stdbool.h>
 
 /* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC     "open.c", 354, FAILTEST_MALLOC
-#define URANDOM_OPEN           "open.c", 62, FAILTEST_OPEN
-#define URANDOM_READ           "open.c", 42, FAILTEST_READ
+#define INITIAL_TDB_MALLOC     "open.c", 343, FAILTEST_MALLOC
+#define URANDOM_OPEN           "open.c", 61, FAILTEST_OPEN
+#define URANDOM_READ           "open.c", 41, FAILTEST_READ
 
 bool exit_check_log(struct failtest_call *history, unsigned num);
 bool failmatch(const struct failtest_call *call,
index 6cb889f4d10cef2f948f4155a5a6a495100cf2f1..e2cde96a96a7570b94b4c35f8c10bb6c97a3e5c4 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
                attr.base.attr = TDB_ATTRIBUTE_HASH;
                ok1(tdb_get_attribute(tdb, &attr) == 0);
                ok1(attr.base.attr == TDB_ATTRIBUTE_HASH);
-               ok1(attr.hash.fn == jenkins_hash);
+               ok1(attr.hash.fn == tdb_jenkins_hash);
                attr.base.attr = TDB_ATTRIBUTE_FLOCK;
                ok1(tdb_get_attribute(tdb, &attr) == 0);
                ok1(attr.base.attr == TDB_ATTRIBUTE_FLOCK);