aboutsummaryrefslogtreecommitdiffstats
path: root/src/tree.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tree.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/tree.h b/src/tree.h
new file mode 100644
index 000000000..737f914d2
--- /dev/null
+++ b/src/tree.h
@@ -0,0 +1,36 @@
+#define CHILDREN_PER_NODE 3
+#define DATA_PER_NODE 2
+
+typedef struct _TreeNode
+{
+ void * data[DATA_PER_NODE];
+ struct _TreeNode * parent;
+ struct _TreeNode * children[CHILDREN_PER_NODE];
+ unsigned dataCount;
+} TreeNode;
+
+typedef int (*TreeCompareDataFunction)(void * data1, void * data2);
+typedef void (*TreeFreeDataFunction)(void * data);
+
+typedef struct _Tree
+{
+ TreeCompareDataFunction compareData;
+ TreeFreeDataFunction freeData;
+ TreeNode * rootNode;
+} Tree;
+
+typedef struct _TreeIterator
+{
+ Tree * tree;
+ TreeNode * node;
+ unsigned which;
+} TreeIterator;
+
+Tree * MakeTree(TreeCompareDataFunction compareFunc,
+ TreeFreeDataFunction freeData);
+
+void SetIteratorToBegin(TreeIterator * iter, Tree * tree);
+
+int InsertIntoTree(Tree * tree, void * data);
+
+void DeleteFromTree(Tree * tree, void * data);