]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/hash.c
tdb2: allow multiple chain locks.
[ccan] / ccan / tdb2 / hash.c
index b1307d985bef413edc2ebea3bb0fe2eaec4e16b0..1359cfecd66dc6280e3314e78fd2e7e5ea91c8bd 100644 (file)
 */
 #include "private.h"
 #include <assert.h>
 */
 #include "private.h"
 #include <assert.h>
-#include <ccan/hash/hash.h>
-
-static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
-                            void *arg)
-{
-       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);
-}
-
-void tdb_hash_init(struct tdb_context *tdb)
-{
-       tdb->hashfn = jenkins_hash;
-}
 
 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
 {
 
 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
 {
-       return tdb->hashfn(ptr, len, tdb->hash_seed, tdb->hash_data);
+       return tdb->hash_fn(ptr, len, tdb->hash_seed, tdb->hash_data);
 }
 
 uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
 }
 
 uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
@@ -88,7 +72,7 @@ static tdb_bool_err key_matches(struct tdb_context *tdb,
        const char *rkey;
 
        if (rec_key_length(rec) != key->dsize) {
        const char *rkey;
 
        if (rec_key_length(rec) != key->dsize) {
-               add_stat(tdb, compare_wrong_keylen, 1);
+               tdb->stats.compare_wrong_keylen++;
                return ret;
        }
 
                return ret;
        }
 
@@ -99,7 +83,7 @@ static tdb_bool_err key_matches(struct tdb_context *tdb,
        if (memcmp(rkey, key->dptr, key->dsize) == 0)
                ret = true;
        else
        if (memcmp(rkey, key->dptr, key->dsize) == 0)
                ret = true;
        else
-               add_stat(tdb, compare_wrong_keycmp, 1);
+               tdb->stats.compare_wrong_keycmp++;
        tdb_access_release(tdb, rkey);
        return ret;
 }
        tdb_access_release(tdb, rkey);
        return ret;
 }
@@ -114,10 +98,10 @@ static tdb_bool_err match(struct tdb_context *tdb,
        tdb_off_t off;
        enum TDB_ERROR ecode;
 
        tdb_off_t off;
        enum TDB_ERROR ecode;
 
-       add_stat(tdb, compares, 1);
+       tdb->stats.compares++;
        /* Desired bucket must match. */
        if (h->home_bucket != (val & TDB_OFF_HASH_GROUP_MASK)) {
        /* Desired bucket must match. */
        if (h->home_bucket != (val & TDB_OFF_HASH_GROUP_MASK)) {
-               add_stat(tdb, compare_wrong_bucket, 1);
+               tdb->stats.compare_wrong_bucket++;
                return false;
        }
 
                return false;
        }
 
@@ -125,7 +109,7 @@ static tdb_bool_err match(struct tdb_context *tdb,
        if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
            != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
                    TDB_OFF_UPPER_STEAL_EXTRA)) {
        if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
            != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
                    TDB_OFF_UPPER_STEAL_EXTRA)) {
-               add_stat(tdb, compare_wrong_offsetbits, 1);
+               tdb->stats.compare_wrong_offsetbits++;
                return false;
        }
 
                return false;
        }
 
@@ -136,7 +120,7 @@ static tdb_bool_err match(struct tdb_context *tdb,
        }
 
        if ((h->h & ((1 << 11)-1)) != rec_hash(rec)) {
        }
 
        if ((h->h & ((1 << 11)-1)) != rec_hash(rec)) {
-               add_stat(tdb, compare_wrong_rechash, 1);
+               tdb->stats.compare_wrong_rechash++;
                return false;
        }
 
                return false;
        }
 
@@ -508,11 +492,11 @@ static enum TDB_ERROR expand_group(struct tdb_context *tdb, struct hash_info *h)
        bucket = fullest_bucket(tdb, h->group, h->home_bucket);
 
        if (h->hash_used == 64) {
        bucket = fullest_bucket(tdb, h->group, h->home_bucket);
 
        if (h->hash_used == 64) {
-               add_stat(tdb, alloc_chain, 1);
+               tdb->stats.alloc_chain++;
                subsize = sizeof(struct tdb_chain);
                magic = TDB_CHAIN_MAGIC;
        } else {
                subsize = sizeof(struct tdb_chain);
                magic = TDB_CHAIN_MAGIC;
        } else {
-               add_stat(tdb, alloc_subhash, 1);
+               tdb->stats.alloc_subhash++;
                subsize = (sizeof(tdb_off_t) << TDB_SUBLEVEL_HASH_BITS);
                magic = TDB_HTABLE_MAGIC;
        }
                subsize = (sizeof(tdb_off_t) << TDB_SUBLEVEL_HASH_BITS);
                magic = TDB_HTABLE_MAGIC;
        }