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). */ hash(const void * elem,void * unused UNNEEDED)11static size_t hash(const void *elem, void *unused UNNEEDED) 12 { 13 size_t h = *(uint64_t *)elem / 2; 14 return h; 15 } 16 main(void)17int main(void) 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 htable_init(&ht, hash, NULL); 28 for (i = 0; i < NUM_VALS; i++) { 29 ok1(ht_max(&ht) >= i); 30 ok1(ht_max(&ht) <= i * 2); 31 htable_add(&ht, hash(&val[i], NULL), &val[i]); 32 } 33 htable_clear(&ht); 34 35 return exit_status(); 36 } 37