1 #include <ccan/htable/htable.h>
2 #include <ccan/htable/htable.c>
3 #include <ccan/tap/tap.h>
10 /* Hash is simply key itself. */
11 static size_t hash(const void *e, void *unused)
13 struct data *d = (struct data *)e;
18 static bool eq(const void *e, void *k)
20 struct data *d = (struct data *)e;
21 size_t *key = (size_t *)k;
23 return (d->key == *key);
33 d1 = malloc(sizeof(struct data));
35 d0 = malloc(sizeof(struct data));
38 htable_init(&table, hash, NULL);
40 htable_add(&table, d0->key, d0);
41 htable_add(&table, d1->key, d1);
43 ok1(table.elems == 2);
44 ok1(htable_get(&table, 1, eq, &d1->key) == d1);
45 ok1(htable_get(&table, 0, eq, &d0->key) == d0);
48 /* Now add in reverse order, should still be OK. */
49 htable_add(&table, d1->key, d1);
50 htable_add(&table, d0->key, d0);
52 ok1(table.elems == 2);
53 ok1(htable_get(&table, 1, eq, &d1->key) == d1);
54 ok1(htable_get(&table, 0, eq, &d0->key) == d0);