| 1 # Tree |
1 # Tree |
| 2 |
2 |
| 3 <warning> |
3 <warning> |
| 4 New Feature - will be documented soon! |
4 TODO: intro text |
| 5 </warning> |
5 </warning> |
| 6 |
6 |
| 7 <!-- |
7 ```C |
| 8 ## Undocumented Symbols (TODO) |
8 #include <cx/tree.h> |
| 9 |
9 |
| 10 ### cx_tree_add |
10 typedef void *(*cx_tree_node_create_func)( |
| 11 ### cx_tree_add_array |
11 const void *data, void *context); |
| 12 ### cxTreeAddChild |
12 |
| 13 ### cxTreeAddChildNode |
13 typedef int (*cx_tree_search_data_func)( |
| 14 ### cx_tree_add_iter |
14 const void *node, const void *data); |
| 15 ### cx_tree_add_look_around_depth |
15 |
| 16 ### cxTreeCreate |
16 typedef int (*cx_tree_search_func)( |
| 17 ### cxTreeCreateWrapped |
17 const void *node, const void *new_node); |
| 18 ### cxTreeDepth |
18 |
| 19 ### cxTreeDestroyNode |
19 typedef void (*cx_tree_relink_func)( |
| 20 ### cxTreeDestroySubtree |
20 void *node, const void *old_parent, const void *new_parent); |
| 21 ### cxTreeFree |
21 |
| 22 ### cx_tree_iterator |
22 #define CX_TREE_NODE_BASE(type) |
| 23 ### cx_tree_link |
23 |
| 24 ### cxTreeRemoveNode |
24 #define cx_tree_node_base_layout |
| 25 ### cxTreeRemoveSubtree |
25 ``` |
| 26 ### cx_tree_search |
26 |
| 27 ### cx_tree_search_data |
27 ## Create |
| 28 ### cxTreeSetParent |
28 |
| 29 ### cxTreeSubtreeDepth |
29 ```C |
| 30 ### cxTreeSubtreeSize |
30 #include <cx/tree.h> |
| 31 ### cx_tree_unlink |
31 |
| 32 ### cx_tree_visitor |
32 CxTree *cxTreeCreate(const CxAllocator *allocator, |
| 33 --> |
33 cx_tree_node_create_func create_func, |
| |
34 cx_tree_search_func search_func, |
| |
35 cx_tree_search_data_func search_data_func, |
| |
36 ptrdiff_t loc_parent, |
| |
37 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
38 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
39 |
| |
40 CxTree *cxTreeCreateSimple(const CxAllocator *allocator, |
| |
41 cx_tree_node_create_func create_func, |
| |
42 cx_tree_search_func search_func, |
| |
43 cx_tree_search_data_func search_data_func); |
| |
44 |
| |
45 CxTree *cxTreeCreateWrapped(const CxAllocator *allocator, |
| |
46 void *root, |
| |
47 ptrdiff_t loc_parent, |
| |
48 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
49 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
50 ``` |
| |
51 |
| |
52 <warning> |
| |
53 TODO: document |
| |
54 </warning> |
| |
55 |
| |
56 ## Add Nodes |
| |
57 |
| |
58 ```C |
| |
59 #include <cx/tree.h> |
| |
60 |
| |
61 void cx_tree_link(void *parent, void *node, ptrdiff_t loc_parent, |
| |
62 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
63 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
64 |
| |
65 extern unsigned int cx_tree_add_look_around_depth; |
| |
66 |
| |
67 size_t cx_tree_add_iter(struct cx_iterator_base_s *iter, size_t n, |
| |
68 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, |
| |
69 void *cdata, void **failed, void *root, |
| |
70 ptrdiff_t loc_parent, |
| |
71 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
72 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
73 |
| |
74 size_t cx_tree_add_array(const void *src, size_t n, size_t elem_size, |
| |
75 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, |
| |
76 void *cdata, void **failed, void *root, |
| |
77 ptrdiff_t loc_parent, |
| |
78 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
79 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
80 |
| |
81 int cx_tree_add(const void *src, |
| |
82 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc, |
| |
83 void *cdata, void **cnode, void *root, |
| |
84 ptrdiff_t loc_parent, |
| |
85 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
86 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
87 |
| |
88 |
| |
89 int cxTreeAddChild(CxTree *tree, void *parent, const void *data); |
| |
90 |
| |
91 void cxTreeAddChildNode(CxTree *tree, void *parent, void *child); |
| |
92 |
| |
93 void cxTreeSetParent(CxTree *tree, void *parent, void *child); |
| |
94 |
| |
95 int cxTreeInsert(CxTree *tree, const void *data); |
| |
96 |
| |
97 size_t cxTreeInsertIter(CxTree *tree, CxIteratorBase *iter, size_t n); |
| |
98 |
| |
99 size_t cxTreeInsertArray(CxTree *tree, const void *data, |
| |
100 size_t elem_size, size_t n); |
| |
101 ``` |
| |
102 |
| |
103 <warning> |
| |
104 TODO: document |
| |
105 </warning> |
| |
106 |
| |
107 ## Size and Depth |
| |
108 |
| |
109 ```C |
| |
110 #include <cx/tree.h> |
| |
111 |
| |
112 size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root); |
| |
113 |
| |
114 size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root); |
| |
115 |
| |
116 size_t cxTreeDepth(CxTree *tree); |
| |
117 ``` |
| |
118 |
| |
119 <warning> |
| |
120 TODO: document |
| |
121 </warning> |
| |
122 |
| |
123 ## Search |
| |
124 |
| |
125 ```C |
| |
126 #include <cx/tree.h> |
| |
127 |
| |
128 #define CX_TREE_SEARCH_INFINITE_DEPTH |
| |
129 |
| |
130 int cx_tree_search_data(const void *root, size_t depth, |
| |
131 const void *data, cx_tree_search_data_func sfunc, |
| |
132 void **result, ptrdiff_t loc_children, ptrdiff_t loc_next); |
| |
133 |
| |
134 int cx_tree_search(const void *root, size_t depth, |
| |
135 const void *node, cx_tree_search_func sfunc, |
| |
136 void **result, ptrdiff_t loc_children, ptrdiff_t loc_next); |
| |
137 |
| |
138 void *cxTreeFind(CxTree *tree, const void *data); |
| |
139 |
| |
140 void *cxTreeFindInSubtree(CxTree *tree, const void *data, |
| |
141 void *subtree_root, size_t max_depth); |
| |
142 ``` |
| |
143 |
| |
144 <warning> |
| |
145 TODO: document |
| |
146 </warning> |
| |
147 |
| |
148 ## Iterator and Visitor |
| |
149 |
| |
150 ```C |
| |
151 #include <cx/tree.h> |
| |
152 |
| |
153 CxTreeIterator cx_tree_iterator(void *root, bool visit_on_exit, |
| |
154 ptrdiff_t loc_children, ptrdiff_t loc_next); |
| |
155 |
| |
156 CxTreeIterator cxTreeIterate(CxTree *tree, bool visit_on_exit); |
| |
157 |
| |
158 CxTreeIterator cxTreeIterateSubtree(CxTree *tree, |
| |
159 void *node, bool visit_on_exit); |
| |
160 |
| |
161 #define cxTreeIteratorContinue(iter) |
| |
162 |
| |
163 void cxTreeIteratorDispose(CxTreeIterator *iter); |
| |
164 |
| |
165 |
| |
166 CxTreeVisitor cx_tree_visitor(void *root, |
| |
167 ptrdiff_t loc_children, ptrdiff_t loc_next); |
| |
168 |
| |
169 CxTreeVisitor cxTreeVisit(CxTree *tree); |
| |
170 |
| |
171 CxTreeVisitor cxTreeVisitSubtree(CxTree *tree, void *node) |
| |
172 |
| |
173 #define cxTreeVisitorContinue(visitor) |
| |
174 |
| |
175 void cxTreeVisitorDispose(CxTreeVisitor *visitor); |
| |
176 ``` |
| |
177 |
| |
178 <warning> |
| |
179 TODO: document |
| |
180 </warning> |
| |
181 |
| |
182 ## Remove |
| |
183 |
| |
184 ```C |
| |
185 #include <cx/tree.h> |
| |
186 |
| |
187 void cx_tree_unlink(void *node, ptrdiff_t loc_parent, |
| |
188 ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
| |
189 ptrdiff_t loc_prev, ptrdiff_t loc_next); |
| |
190 |
| |
191 int cxTreeRemoveNode(CxTree *tree, void *node, |
| |
192 cx_tree_relink_func relink_func); |
| |
193 |
| |
194 void cxTreeRemoveSubtree(CxTree *tree, void *node); |
| |
195 ``` |
| |
196 |
| |
197 <warning> |
| |
198 TODO: document |
| |
199 </warning> |
| |
200 |
| |
201 ## Dispose |
| |
202 |
| |
203 ```C |
| |
204 #include <cx/tree.h> |
| |
205 |
| |
206 int cxTreeDestroyNode(CxTree *tree, void *node, |
| |
207 cx_tree_relink_func relink_func); |
| |
208 |
| |
209 void cxTreeDestroySubtree(CxTree *tree, void *node); |
| |
210 |
| |
211 void cxTreeClear(CxTree *tree); |
| |
212 |
| |
213 void cxTreeFree(CxTree *tree); |
| |
214 ``` |
| |
215 |
| |
216 <warning> |
| |
217 TODO: document |
| |
218 </warning> |
| 34 |
219 |
| 35 <seealso> |
220 <seealso> |
| 36 <category ref="apidoc"> |
221 <category ref="apidoc"> |
| 37 <a href="https://ucx.sourceforge.io/api/tree_8h.html">tree.h</a> |
222 <a href="https://ucx.sourceforge.io/api/tree_8h.html">tree.h</a> |
| 38 </category> |
223 </category> |