htable: fix tools/speed.
[ccan] / ccan / htable / tools / speed.c
index d5a3f6520fb2267f61c4a80c2faef27604a8ef5d..194f11201f01c9d08aa5647f4a8436c1175a03de 100644 (file)
@@ -4,6 +4,7 @@
 #include <ccan/hash/hash.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -28,9 +29,9 @@ static size_t hash_obj(const unsigned int *key)
        return hashl(key, 1, 0);
 }
 
-static bool cmp(const unsigned int *key1, const unsigned int *key2)
+static bool cmp(const struct object *object, const unsigned int *key)
 {
-       return *key1 == *key2;
+       return object->key == *key;
 }
 
 HTABLE_DEFINE_TYPE(struct object, objkey, hash_obj, cmp, obj);
@@ -73,8 +74,11 @@ static size_t perfect(const struct htable *ht)
                if (!entry_is_valid(ht->table[i]))
                        continue;
                if (hash_bucket(ht, ht->rehash(get_raw_ptr(ht, ht->table[i]),
-                                              ht->priv)) == i)
+                                              ht->priv)) == i) {
+                       assert((ht->table[i] & ht->perfect_bit)
+                              == ht->perfect_bit);
                        placed_perfect++;
+               }
        }
        return placed_perfect;
 }
@@ -327,7 +331,7 @@ int main(int argc, char *argv[])
        fflush(stdout);
        gettimeofday(&start, NULL);
        for (i = 0; i < num; i++) {
-               unsigned int n = num * 6 + i * 9;
+               unsigned int n = num * (5 + 9) + i * 9;
                if (htable_obj_get(ht, &n))
                        abort();
        }