aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib/data/generic_tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/lib/data/generic_tree.h')
-rw-r--r--src/kernel/lib/data/generic_tree.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/kernel/lib/data/generic_tree.h b/src/kernel/lib/data/generic_tree.h
new file mode 100644
index 0000000..3a630bc
--- /dev/null
+++ b/src/kernel/lib/data/generic_tree.h
@@ -0,0 +1,36 @@
+#ifndef MELVIX_GENERIC_TREE_H
+#define MELVIX_GENERIC_TREE_H
+
+#include <kernel/lib/data/list.h>
+
+typedef struct gtreenode {
+ list_t *children;
+ void *value;
+} gtreenode_t;
+
+typedef struct gtree {
+ gtreenode_t *root;
+} gtree_t;
+
+gtree_t *tree_create();
+
+gtreenode_t *treenode_create(void *value);
+
+gtreenode_t *tree_insert(gtree_t *tree, gtreenode_t *subroot, void *value);
+
+gtreenode_t *tree_find_parent(gtree_t *tree, gtreenode_t *remove_node, int *child_index);
+
+gtreenode_t *tree_find_parent_recur(gtree_t *tree, gtreenode_t *remove_node, gtreenode_t *subroot,
+ int *child_index);
+
+void tree_remove(gtree_t *tree, gtreenode_t *remove_node);
+
+void tree2list_recur(gtreenode_t *subroot, list_t *list);
+
+void tree2list(gtree_t *tree, list_t *list);
+
+void tree2array(gtree_t *tree, void **array, int *size);
+
+void tree2array_recur(gtreenode_t *subroot, void **array, int *size);
+
+#endif \ No newline at end of file