aboutsummaryrefslogtreecommitdiff
path: root/bpt_test.c
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-08-31 18:26:07 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-08-31 18:26:07 +0200
commit257ad41d50d443b986580cf067fef3465299d8ab (patch)
tree824b4d06a1120de9e794fcf03934a5894f26d5f0 /bpt_test.c
Initial commit.
Diffstat (limited to 'bpt_test.c')
-rw-r--r--bpt_test.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/bpt_test.c b/bpt_test.c
new file mode 100644
index 0000000..9f57152
--- /dev/null
+++ b/bpt_test.c
@@ -0,0 +1,64 @@
+#include "stdio.h"
+#include "stdlib.h"
+#include "bitmapped_patricia_tree.h"
+
+void print_deallocation(bpt_key_t key, void *value) {
+ printf("Deallocated: %s\n", value);
+}
+
+void print_tree(bpt_t b) {
+ int i;
+ for (i = 0; i < 10; i++) {
+ if (bpt_has_key(b, i)) {
+ printf(" %d -> %s\n", i, bpt_get(b, i));
+ }
+ }
+}
+
+bpt_t bpt_assoc_and_release(bpt_t bpt, bpt_key_t key, void *value) {
+ bpt_t new_bpt = bpt_assoc(bpt, key, value);
+ bpt_release(bpt);
+ return new_bpt;
+}
+
+bpt_t bpt_dissoc_and_release(bpt_t bpt, bpt_key_t key) {
+ bpt_t new_bpt = bpt_dissoc(bpt, key);
+ bpt_release(bpt);
+ return new_bpt;
+}
+
+int main() {
+ bpt_t b1, b2;
+
+ b1 = bpt_assoc (NULL, 0, "zero");
+ b1 = bpt_assoc_and_release(b1, 1, "one");
+ b1 = bpt_assoc_and_release(b1, 2, "two");
+ b1 = bpt_assoc_and_release(b1, 3, "three");
+ b1 = bpt_assoc_and_release(b1, 4, "four");
+ bpt_seal(b1);
+
+ b2 = bpt_assoc (b1, 0, "null");
+ b2 = bpt_assoc_and_release(b2, 3, "a triple");
+
+ b1 = bpt_assoc_and_release(b1, 5, "five");
+
+ printf("Map 1:\n");
+ print_tree(b1);
+ printf("\nMap 2:\n");
+ print_tree(b2);
+
+ bpt_set_dealloc_hook(b1, 0, print_deallocation);
+ bpt_set_dealloc_hook(b1, 1, print_deallocation);
+ bpt_set_dealloc_hook(b1, 2, print_deallocation);
+ bpt_set_dealloc_hook(b1, 3, print_deallocation);
+ bpt_set_dealloc_hook(b1, 4, print_deallocation);
+ bpt_set_dealloc_hook(b1, 5, print_deallocation);
+
+ bpt_set_dealloc_hook(b2, 0, print_deallocation);
+ bpt_set_dealloc_hook(b2, 3, print_deallocation);
+
+ bpt_release(b1);
+ bpt_release(b2);
+
+ return EXIT_SUCCESS;
+}