aboutsummaryrefslogtreecommitdiff
path: root/src/common/include/kogata/btree.h
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2016-07-15 23:12:14 +0200
committerAlex Auvolat <alex@adnab.me>2016-07-15 23:12:14 +0200
commit32407e728971006ed3d0885e01c22fb66c8adc57 (patch)
tree89483d39e8e2638383f815d4e73b647334fe2fe9 /src/common/include/kogata/btree.h
parentba4e59a1d687173ac5cfa74d26d71d6059dc6bc6 (diff)
downloadkogata-32407e728971006ed3d0885e01c22fb66c8adc57.tar.gz
kogata-32407e728971006ed3d0885e01c22fb66c8adc57.zip
Move stuff around, again
Diffstat (limited to 'src/common/include/kogata/btree.h')
-rw-r--r--src/common/include/kogata/btree.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/include/kogata/btree.h b/src/common/include/kogata/btree.h
new file mode 100644
index 0000000..e796a2d
--- /dev/null
+++ b/src/common/include/kogata/btree.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <kogata/algo.h>
+
+// A btree may contain several bindings for the same key (in that case they are not ordered)
+// - btree_find returns any item with matching key, or null if none exists
+// - btree_lower returns any item with matching key, or if none returns last item with smaller key
+// - btree_upper returns any item with matching key, or if none returns first item with bigger key
+// - btree_remove removes *all bindings* with matching key
+// - btree_remove_v removes bindings with matching *key and value*
+// - btree_iter_on calls iterator function on all bindings with matching key
+
+// Memory management is same as for hashtbl (a kv_iter_fun_t is called when an item is released)
+
+struct btree;
+typedef struct btree btree_t;
+
+btree_t* create_btree(key_cmp_fun_t cf, kv_iter_fun_t on_release);
+void delete_btree(btree_t *t);
+
+bool btree_add(btree_t *t, void* key, void* val);
+void btree_remove(btree_t *t, const void* key);
+void btree_remove_v(btree_t *t, const void* key, const void* value);
+
+void* btree_find(btree_t *i, const void* key);
+void* btree_lower(btree_t *i, const void* key, void** actual_key);
+void* btree_upper(btree_t *i, const void* key, void** actual_key);
+void btree_iter(btree_t *i, kv_iter_fun_t f);
+void btree_iter_on(btree_t *i, const void* key, kv_iter_fun_t f);
+
+size_t btree_count(btree_t *i);
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/