]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/test/run-type.c
htable: start empty.
[ccan] / ccan / htable / test / run-type.c
index 1ef42a4c35e87858174666c80b760af2b686dde9..aca9c59488240f7e3b9e0090ac15256120c7a59f 100644 (file)
@@ -4,9 +4,12 @@
 #include <stdbool.h>
 #include <string.h>
 
-#define NUM_VALS (1 << HTABLE_BASE_BITS)
+#define NUM_BITS 7
+#define NUM_VALS (1 << NUM_BITS)
 
 struct obj {
+       /* Makes sure we don't try to treat and obj as a key or vice versa */
+       unsigned char unused;
        unsigned int key;
 };
 
@@ -21,13 +24,13 @@ static const unsigned int *objkey(const struct obj *obj)
 static size_t objhash(const unsigned int *key)
 {
        size_t h = *key / 2;
-       h |= -1UL << HTABLE_BASE_BITS;
+       h |= -1UL << NUM_BITS;
        return h;
 }
 
-static bool cmp(const unsigned int *key1, const unsigned int *key2)
+static bool cmp(const struct obj *obj, const unsigned int *key)
 {
-       return *key1 == *key2;
+       return obj->key == *key;
 }
 
 HTABLE_DEFINE_TYPE(struct obj, objkey, objhash, cmp, obj);
@@ -119,15 +122,15 @@ int main(int argc, char *argv[])
        dne = i;
 
        ht = htable_obj_new();
-       ok1(((struct htable *)ht)->max < (1 << ((struct htable *)ht)->bits));
-       ok1(((struct htable *)ht)->bits == HTABLE_BASE_BITS);
+       ok1(((struct htable *)ht)->max == 0);
+       ok1(((struct htable *)ht)->bits == 0);
 
        /* We cannot find an entry which doesn't exist. */
        ok1(!htable_obj_get(ht, &dne));
 
-       /* Fill it, it should increase in size (once). */
+       /* Fill it, it should increase in size. */
        add_vals(ht, val, NUM_VALS);
-       ok1(((struct htable *)ht)->bits == HTABLE_BASE_BITS + 1);
+       ok1(((struct htable *)ht)->bits == NUM_BITS + 1);
        ok1(((struct htable *)ht)->max < (1 << ((struct htable *)ht)->bits));
 
        /* Mask should be set. */