X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhtable%2Ftest%2Frun-size.c;fp=ccan%2Fhtable%2Ftest%2Frun-size.c;h=01e4bb41acf7ad526dde9e5d3f1fa726ddc84f70;hp=0000000000000000000000000000000000000000;hb=45f24da35118db441e6153f02f6ddd937da1fa1c;hpb=cbca0212706dfc855085aa18feb7a4efcc779901 diff --git a/ccan/htable/test/run-size.c b/ccan/htable/test/run-size.c new file mode 100644 index 00000000..01e4bb41 --- /dev/null +++ b/ccan/htable/test/run-size.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +#define NUM_VALS 512 + +/* We use the number divided by two as the hash (for lots of + collisions). */ +static size_t hash(const void *elem, void *unused) +{ + size_t h = *(uint64_t *)elem / 2; + return h; +} + +int main(int argc, char *argv[]) +{ + struct htable *ht; + uint64_t val[NUM_VALS]; + unsigned int i; + + plan_tests((NUM_VALS) * 2); + for (i = 0; i < NUM_VALS; i++) + val[i] = i; + + ht = htable_new(hash, NULL); + for (i = 0; i < NUM_VALS; i++) { + ok1(ht->max >= i); + ok1(ht->max <= i * 2); + htable_add(ht, hash(&val[i], NULL), &val[i]); + } + htable_free(ht); + + return exit_status(); +}