]> git.ozlabs.org Git - ccan/blob - ccan/htable/test/run-size.c
01e4bb41acf7ad526dde9e5d3f1fa726ddc84f70
[ccan] / ccan / htable / test / run-size.c
1 #include <ccan/htable/htable.h>
2 #include <ccan/htable/htable.c>
3 #include <ccan/tap/tap.h>
4 #include <stdbool.h>
5 #include <string.h>
6
7 #define NUM_VALS 512
8
9 /* We use the number divided by two as the hash (for lots of
10    collisions). */
11 static size_t hash(const void *elem, void *unused)
12 {
13         size_t h = *(uint64_t *)elem / 2;
14         return h;
15 }
16
17 int main(int argc, char *argv[])
18 {
19         struct htable *ht;
20         uint64_t val[NUM_VALS];
21         unsigned int i;
22
23         plan_tests((NUM_VALS) * 2);
24         for (i = 0; i < NUM_VALS; i++)
25                 val[i] = i;
26
27         ht = htable_new(hash, NULL);
28         for (i = 0; i < NUM_VALS; i++) {
29                 ok1(ht->max >= i);
30                 ok1(ht->max <= i * 2);
31                 htable_add(ht, hash(&val[i], NULL), &val[i]);
32         }
33         htable_free(ht);
34
35         return exit_status();
36 }