aboutsummaryrefslogtreecommitdiff
path: root/src/common/include/algo.h
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 17:36:03 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 17:36:03 +0100
commit74ea640f40285220dfa93492a143a35426b867d1 (patch)
tree726fea60a2e0a9f835212228238bdc479012b2f8 /src/common/include/algo.h
parentba53137f1b687b1c9cbd66fbe306ed1bf6d0cccb (diff)
downloadkogata-74ea640f40285220dfa93492a143a35426b867d1.tar.gz
kogata-74ea640f40285220dfa93492a143a35426b867d1.zip
Add binary tree implementation. NOT TESTED, FULL OF BUGS.
Diffstat (limited to 'src/common/include/algo.h')
-rw-r--r--src/common/include/algo.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common/include/algo.h b/src/common/include/algo.h
new file mode 100644
index 0000000..80af052
--- /dev/null
+++ b/src/common/include/algo.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#define MIN(a, b) ((a)<(b)?(a):(b))
+#define MAX(a, b) ((a)>(b)?(a):(b))
+#define ABS(a) ((a)<0?-(a):(a))
+
+// ============================================================= //
+// FUNCTION TYPES FOR KEY-VALUE DATA STRUCTURES (HASHTBL, BTREE) //
+
+typedef uint32_t hash_t;
+typedef hash_t (*hash_fun_t)(const void*);
+
+typedef int (*key_cmp_fun_t)(const void*, const void*);
+typedef bool (*key_eq_fun_t)(const void*, const void*);
+
+typedef void (*kv_iter_fun_t)(void* key, void* value);
+
+// void* is considered as an unsigned integer (and not a pointer)
+hash_t id_hash_fun(const void* v);
+bool id_key_eq_fun(const void* a, const void* b);
+int id_key_cmp_fun(const void* a, const void* b);
+
+// void* considered as char*
+hash_t str_hash_fun(const void* v);
+bool str_key_eq_fun(const void* a, const void* b);
+int str_key_cmp_fun(const void* a, const void* b);
+
+// Freeing functions (they are of type kv_iter_fun_t)
+void free_key(void* key, void* val);
+void free_val(void* key, void* val);
+void free_key_val(void* key, void* val);
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/