diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-12-05 16:42:47 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-12-05 16:42:47 +1030 |
commit | 19409ddaf2414dd1d8ef183c834b37c8767034b0 (patch) | |
tree | dac5462b73e3588729d80dd4be44bcadf949f4c3 /lib/ccan/htable/test/run-size.c | |
parent | 1beb793664dba184892b23dced4a3676fb94ff9f (diff) | |
download | samba-19409ddaf2414dd1d8ef183c834b37c8767034b0.tar.gz samba-19409ddaf2414dd1d8ef183c834b37c8767034b0.tar.bz2 samba-19409ddaf2414dd1d8ef183c834b37c8767034b0.zip |
lib/ccan/htable: start empty.
There's no real reason to start with 128 entries.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 45f24da35118db441e6153f02f6ddd937da1fa1c)
Diffstat (limited to 'lib/ccan/htable/test/run-size.c')
-rw-r--r-- | lib/ccan/htable/test/run-size.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/ccan/htable/test/run-size.c b/lib/ccan/htable/test/run-size.c new file mode 100644 index 0000000000..01e4bb41ac --- /dev/null +++ b/lib/ccan/htable/test/run-size.c @@ -0,0 +1,36 @@ +#include <ccan/htable/htable.h> +#include <ccan/htable/htable.c> +#include <ccan/tap/tap.h> +#include <stdbool.h> +#include <string.h> + +#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(); +} |