summaryrefslogtreecommitdiff
path: root/tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'tree.h')
-rwxr-xr-xtree.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/tree.h b/tree.h
new file mode 100755
index 0000000..7bc180f
--- /dev/null
+++ b/tree.h
@@ -0,0 +1,54 @@
1#ifndef TREE_H
2#define TREE_H
3
4 #include <stdlib.h>
5
6 /** \file tree.h tree.c
7 * most basic tree-implemenation: this is meant as base for all classes
8 * and kept as simple as possible in order to prevent overheads.
9 * relying classes should therefor be performant and easy to maintain.
10 */
11
12 /** \example ./tst/test.c
13 * This example generates a new tree and adds elements.
14 * and prints them on stdout.
15 */
16
17 /// basic structure of a tree- every node can have a child and is part of a
18 /// linked list, so it has a next-element
19 typedef struct Tree
20 {
21 const void* data;
22 struct Tree* next;
23 struct Tree* child;
24 } Tree;
25
26 /// creates a new Tree-structure with a dataentry...
27 extern Tree* tree_new(const void* const data);
28
29 /// appends the tree to the bottom (adds element to the list)
30 extern Tree* tree_add(Tree* tree, const void* const data);
31
32 /// appends the tree to the bottom (adds element to the list)
33 extern Tree* tree_addChildTop(Tree* tree, const void* const data);
34
35 /// appends the tree to the bottom (adds element to the list)
36 extern Tree* tree_addtop(Tree* tree, const void* const data);
37
38 /// adds a childnode. same as adding an element to the list of its child
39 extern Tree* tree_addChild(Tree* tree, const void* const data);
40
41 /// frees all nodes (data* has to be freed seperatly)
42 extern void tree_free(Tree* tree, void((*free_function)(const void*)));
43
44 /// adds another tree at the end of the tree-structure (last element addition)
45 extern Tree* tree_join(Tree* tree, Tree* subtree);
46
47 /// extends another tree as child of the given
48 extern Tree* tree_extend(Tree* tree, Tree* subtree);
49
50 /// iterates over all tree-elements, until return-value of fn is NULL
51 /// - uses the return void* from fn() as next function, so that you
52 /// keep the order in deep structures.
53 extern void tree_iterate(Tree* tree, void* (*fn)(const void* data));
54#endif
..