1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #ifndef UCX_TREE_H
37 #define UCX_TREE_H
38
39 #include "common.h"
40
41 #include "iterator.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 typedef struct cx_tree_iterator_s {
61
62
63
64 CX_ITERATOR_BASE;
65
66
67
68 bool skip;
69
70
71
72
73 bool visit_on_exit;
74
75
76
77 bool exiting;
78
79
80
81 ptrdiff_t loc_children;
82
83
84
85 ptrdiff_t loc_next;
86
87
88
89 size_t counter;
90
91
92
93
94
95 void *node;
96
97
98
99
100 void *node_next;
101
102
103
104
105
106
107
108 void **stack;
109
110
111
112 size_t stack_capacity;
113 union {
114
115
116
117 size_t stack_size;
118
119
120
121 size_t depth;
122 };
123 } CxTreeIterator;
124
125
126
127
128 struct cx_tree_visitor_queue_s {
129
130
131
132 void *node;
133
134
135
136 size_t depth;
137
138
139
140 struct cx_tree_visitor_queue_s *next;
141 };
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 typedef struct cx_tree_visitor_s {
160
161
162
163 CX_ITERATOR_BASE;
164
165
166
167 bool skip;
168
169
170
171 ptrdiff_t loc_children;
172
173
174
175 ptrdiff_t loc_next;
176
177
178
179 size_t counter;
180
181
182
183
184
185 void *node;
186
187
188
189 size_t depth;
190
191
192
193 struct cx_tree_visitor_queue_s *queue_next;
194
195
196
197 struct cx_tree_visitor_queue_s *queue_last;
198 } CxTreeVisitor;
199
200
201
202
203
204 __attribute__((__nonnull__))
205 static inline
void cxTreeIteratorDispose(CxTreeIterator *iter) {
206 free(iter->stack);
207 iter->stack =
NULL;
208 }
209
210
211
212
213
214 __attribute__((__nonnull__))
215 static inline
void cxTreeVisitorDispose(CxTreeVisitor *visitor) {
216 struct cx_tree_visitor_queue_s *q = visitor->queue_next;
217 while (q !=
NULL) {
218 struct cx_tree_visitor_queue_s *next = q->next;
219 free(q);
220 q = next;
221 }
222 }
223
224
225
226
227
228
229
230 #define cxTreeIteratorContinue(iterator) (iterator).skip = true;
continue
231
232
233
234
235
236
237
238 #define cxTreeVisitorContinue(visitor) cxTreeIteratorContinue(visitor)
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255 __attribute__((__nonnull__))
256 void cx_tree_link(
257 void * restrict parent,
258 void * restrict node,
259 ptrdiff_t loc_parent,
260 ptrdiff_t loc_children,
261 ptrdiff_t loc_prev,
262 ptrdiff_t loc_next
263 );
264
265
266
267
268
269
270
271
272
273
274
275
276
277 __attribute__((__nonnull__))
278 void cx_tree_unlink(
279 void *node,
280 ptrdiff_t loc_parent,
281 ptrdiff_t loc_children,
282 ptrdiff_t loc_prev,
283 ptrdiff_t loc_next
284 );
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310 typedef int (*cx_tree_search_func)(
void const *node,
void const* data);
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336 __attribute__((__nonnull__))
337 int cx_tree_search(
338 void const *root,
339 void const *data,
340 cx_tree_search_func sfunc,
341 void **result,
342 ptrdiff_t loc_children,
343 ptrdiff_t loc_next
344 );
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363 __attribute__((__nonnull__))
364 CxTreeIterator cx_tree_iterator(
365 void *root,
366 bool visit_on_exit,
367 ptrdiff_t loc_children,
368 ptrdiff_t loc_next
369 );
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387 __attribute__((__nonnull__))
388 CxTreeVisitor cx_tree_visitor(
389 void *root,
390 ptrdiff_t loc_children,
391 ptrdiff_t loc_next
392 );
393
394 #ifdef __cplusplus
395 }
396 #endif
397
398 #endif
399