summaryrefslogtreecommitdiff
path: root/ccan/htable/test/run-size.c
diff options
context:
space:
mode:
authorWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
committerWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
commit1b8fbbd843ddeb5fc81c9303db9c590a436d499b (patch)
treea7227dfe8e4fbaee7b1e0b58b24994dce8078f3f /ccan/htable/test/run-size.c
parent37a9cdd2e80386f2c94e14e4f511284ae14c745a (diff)
progress
Diffstat (limited to 'ccan/htable/test/run-size.c')
-rw-r--r--ccan/htable/test/run-size.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/ccan/htable/test/run-size.c b/ccan/htable/test/run-size.c
new file mode 100644
index 0000000..1a2f5cd
--- /dev/null
+++ b/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 UNNEEDED)
+{
+ size_t h = *(uint64_t *)elem / 2;
+ return h;
+}
+
+int main(void)
+{
+ 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;
+
+ htable_init(&ht, 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_clear(&ht);
+
+ return exit_status();
+}