Wed, 31 Dec 2025 15:11:12 +0100
final docs fixes + add release date to the changelog
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved. |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
29 | * @file tree.h |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
30 | * @brief Interface for tree implementations. |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
31 | * @author Mike Becker |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
32 | * @author Olaf Wintermann |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
33 | * @copyright 2-Clause BSD License |
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | */ |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | #ifndef UCX_TREE_H |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #define UCX_TREE_H |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | #include "common.h" |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
41 | #include "collection.h" |
|
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
42 | |
|
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
43 | /** |
| 845 | 44 | * An element in a visitor queue. |
| 45 | */ | |
| 46 | struct cx_tree_visitor_queue_s { | |
| 47 | /** | |
| 48 | * The tree node to visit. | |
| 49 | */ | |
| 50 | void *node; | |
| 51 | /** | |
| 52 | * The depth of the node. | |
|
1308
ce01b482daa3
add explanation of depth to the iterator/visitor field
Mike Becker <universe@uap-core.de>
parents:
1295
diff
changeset
|
53 | * The first visited node has depth 1. |
| 845 | 54 | */ |
| 55 | size_t depth; | |
| 56 | /** | |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
57 | * The next element in the queue or @c NULL. |
| 845 | 58 | */ |
| 59 | struct cx_tree_visitor_queue_s *next; | |
| 60 | }; | |
| 61 | ||
|
1692
56731bb98508
final docs fixes + add release date to the changelog
Mike Becker <universe@uap-core.de>
parents:
1690
diff
changeset
|
62 | /** |
|
56731bb98508
final docs fixes + add release date to the changelog
Mike Becker <universe@uap-core.de>
parents:
1690
diff
changeset
|
63 | * An iterator (DFS) or visitor (BFS) for a tree. |
|
56731bb98508
final docs fixes + add release date to the changelog
Mike Becker <universe@uap-core.de>
parents:
1690
diff
changeset
|
64 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
65 | typedef struct cx_tree_combined_iterator_s { |
|
854
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
66 | /** |
|
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
67 | * Base members. |
|
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
68 | */ |
|
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
69 | CX_ITERATOR_BASE; |
| 845 | 70 | /** |
| 71 | * Offset in the node struct for the children linked list. | |
| 72 | */ | |
| 73 | ptrdiff_t loc_children; | |
| 74 | /** | |
| 75 | * Offset in the node struct for the next pointer. | |
| 76 | */ | |
| 77 | ptrdiff_t loc_next; | |
| 78 | /** | |
| 79 | * The total number of distinct nodes that have been passed so far. | |
|
1512
0dc866c7863b
add the note to the docstrings that tree iterator/visitor counter include the currently visited node
Mike Becker <universe@uap-core.de>
parents:
1426
diff
changeset
|
80 | * This includes the currently visited node. |
| 845 | 81 | */ |
| 82 | size_t counter; | |
| 83 | /** | |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
84 | * The current depth in the tree. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
85 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
86 | size_t depth; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
87 | /** |
| 845 | 88 | * The currently observed node. |
| 89 | * | |
| 90 | * This is the same what cxIteratorCurrent() would return. | |
| 91 | */ | |
| 92 | void *node; | |
| 93 | /** | |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
94 | * Memory for BFS or DFS-specific data. |
| 845 | 95 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
96 | union { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
97 | struct { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
98 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
99 | * Stores a copy of the pointer to the successor of the visited node. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
100 | * Allows freeing a node on exit without corrupting the iteration. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
101 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
102 | void *node_next; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
103 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
104 | * Internal stack. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
105 | * Will be automatically freed once the iterator becomes invalid. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
106 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
107 | * If you want to discard the iterator before, you need to manually |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
108 | * call cxTreeIteratorDispose(). |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
109 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
110 | void **stack; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
111 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
112 | * Internal capacity of the stack. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
113 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
114 | size_t stack_capacity; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
115 | }; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
116 | struct { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
117 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
118 | * The next element in the visitor queue. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
119 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
120 | struct cx_tree_visitor_queue_s *queue_next; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
121 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
122 | * The last element in the visitor queue. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
123 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
124 | struct cx_tree_visitor_queue_s *queue_last; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
125 | }; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
126 | }; |
| 845 | 127 | /** |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
128 | * Indicates whether the subtree below the current node shall be skipped. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
129 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
130 | bool skip; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
131 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
132 | * Set to true, when the iterator shall visit a node again |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
133 | * when all its children have been processed. |
| 845 | 134 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
135 | bool visit_on_exit; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
136 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
137 | * True, if this iterator is currently leaving the node. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
138 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
139 | bool exiting; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
140 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
141 | * Indicates whether the @c iterator (true) or the @c visitor (false) aspect is active. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
142 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
143 | bool use_dfs; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
144 | } CxTreeIterator; |
| 845 | 145 | |
| 146 | /** | |
|
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
147 | * Releases internal memory of the given tree iterator. |
|
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
148 | * @param iter the iterator |
|
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
149 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
150 | CX_EXTERN CX_NONNULL |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
151 | void cxTreeIteratorDispose(CxTreeIterator *iter); |
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
153 | /** |
|
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
154 | * Advises the iterator to skip the subtree below the current node and |
|
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
155 | * also continues the current loop. |
|
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
156 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
157 | * @param iterator (@c CxTreeIterator) the iterator |
|
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
158 | */ |
|
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
159 | #define cxTreeIteratorContinue(iterator) (iterator).skip = true; continue |
|
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
160 | |
|
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
161 | /** |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
162 | * Links a node to a (new) parent. |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
163 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
164 | * If the node already has a parent, it is unlinked, first. |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
165 | * If the parent has children already, the node is @em appended to the list |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
166 | * of all currently existing children. |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
167 | * |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
168 | * @param parent the parent node |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
169 | * @param node the node that shall be linked |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
170 | * @param loc_parent offset in the node struct for the parent pointer |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
171 | * @param loc_children offset in the node struct for the children linked list |
|
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
172 | * @param loc_last_child optional offset in the node struct for the pointer to |
|
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
173 | * the last child in the linked list (negative if there is no such pointer) |
|
921
5a7aa9cf9c3a
make loc_prev in trees optional - fixes #433
Mike Becker <universe@uap-core.de>
parents:
918
diff
changeset
|
174 | * @param loc_prev optional offset in the node struct for the prev pointer |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
175 | * @param loc_next offset in the node struct for the next pointer |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
176 | * @see cx_tree_remove() |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
177 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
178 | CX_EXTERN CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
179 | void cx_tree_add(void *parent, void *node, |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
180 | ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
181 | ptrdiff_t loc_prev, ptrdiff_t loc_next); |
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
183 | /** |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
184 | * Unlinks a node from its parent. |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
185 | * |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
186 | * If the node has no parent, this function does nothing. |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
187 | * |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
188 | * @param node the node that shall be unlinked from its parent |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
189 | * @param loc_parent offset in the node struct for the parent pointer |
|
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
190 | * @param loc_children offset in the node struct for the children linked list |
|
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
191 | * @param loc_last_child optional offset in the node struct for the pointer to |
|
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
192 | * the last child in the linked list (negative if there is no such pointer) |
|
921
5a7aa9cf9c3a
make loc_prev in trees optional - fixes #433
Mike Becker <universe@uap-core.de>
parents:
918
diff
changeset
|
193 | * @param loc_prev optional offset in the node struct for the prev pointer |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
194 | * @param loc_next offset in the node struct for the next pointer |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
195 | * @see cx_tree_add() |
|
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
196 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
197 | CX_EXTERN CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
198 | void cx_tree_remove(void *node, |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
199 | ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
200 | ptrdiff_t loc_prev, ptrdiff_t loc_next); |
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | |
|
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
202 | /** |
|
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
203 | * Macro that can be used instead of the magic value for infinite search depth. |
|
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
204 | */ |
|
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
205 | #define CX_TREE_SEARCH_INFINITE_DEPTH 0 |
|
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
206 | |
|
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
207 | /** |
|
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
208 | * Function pointer for a search function. |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
209 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
210 | * A function of this kind shall check if the specified @p node |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
211 | * contains the given @p data or if one of the children might contain |
|
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
212 | * the data. |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
213 | * |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
214 | * The function should use the returned integer to indicate how close the |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
215 | * match is, where a negative number means that it does not match at all. |
|
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
216 | * Zero means exact match and a positive number is an implementation defined |
|
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
217 | * measure for the distance to an exact match. |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
218 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
219 | * For example, consider a tree that stores file path information. |
|
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
220 | * A node which is describing a parent directory of a searched file shall |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
221 | * return a positive number to indicate that a child node might contain the |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
222 | * searched item. On the other hand, if the node denotes a path that is not a |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
223 | * prefix of the searched filename, the function would return -1 to indicate |
| 859 | 224 | * that the search does not need to be continued in that branch. |
|
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
225 | * |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
226 | * @param node the node that is currently investigated |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
227 | * @param data the data that is searched for |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
228 | * |
|
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
229 | * @return 0 if the node contains the data, |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
230 | * positive if one of the children might contain the data, |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
231 | * negative if neither the node nor the children contains the data |
|
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
232 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
233 | typedef int (*cx_tree_search_func)(const void *node, const void *data); |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
234 | |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
235 | /** |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
236 | * Searches for data in a tree. |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
237 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
238 | * When the data cannot be found exactly, the search function might return the |
|
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
239 | * closest result, which might be a good starting point for adding a new node |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
240 | * to the tree. |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
241 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
242 | * Depending on the tree structure, it is not necessarily guaranteed that the |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
243 | * "closest" match is uniquely defined. This function will search for a node |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
244 | * with the best match according to the @p sfunc (meaning: the return value of |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
245 | * @p sfunc which is closest to zero). If that is also ambiguous, an arbitrary |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
246 | * node matching the criteria is returned. |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
247 | * |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
248 | * @param root the root node |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
249 | * @param max_depth the maximum depth (zero=indefinite, one=just root) |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
250 | * @param data the data to search for |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
251 | * @param sfunc the search function |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
252 | * @param result where the result shall be stored |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
253 | * @param loc_children offset in the node struct for the children linked list |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
254 | * @param loc_next offset in the node struct for the next pointer |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
255 | * @return zero if the node was found exactly, positive if a node was found that |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
256 | * could contain the node (but doesn't right now), negative if the tree does not |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
257 | * contain any node that might be related to the searched data |
|
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
258 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
259 | CX_EXTERN CX_NONNULL_ARG(4, 5) CX_ACCESS_W(5) |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
260 | int cx_tree_search(const void *root, size_t max_depth, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
261 | const void *data, cx_tree_search_func sfunc, void **result, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
262 | ptrdiff_t loc_children, ptrdiff_t loc_next); |
|
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
263 | |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
264 | /** |
| 845 | 265 | * Creates a depth-first iterator for a tree with the specified root node. |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
266 | * |
| 859 | 267 | * @note A tree iterator needs to maintain a stack of visited nodes, which is |
|
1318
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents:
1308
diff
changeset
|
268 | * allocated using the cxDefaultAllocator. |
| 859 | 269 | * When the iterator becomes invalid, this memory is automatically released. |
| 270 | * However, if you wish to cancel the iteration before the iterator becomes | |
| 271 | * invalid by itself, you MUST call cxTreeIteratorDispose() manually to release | |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
272 | * the memory. |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
273 | * |
| 845 | 274 | * @remark The returned iterator does not support cxIteratorFlagRemoval(). |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
275 | * |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
276 | * @param root the root node |
| 859 | 277 | * @param visit_on_exit set to true, when the iterator shall visit a node again |
| 278 | * after processing all children | |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
279 | * @param loc_children offset in the node struct for the children linked list |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
280 | * @param loc_next offset in the node struct for the next pointer |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
281 | * @return the new tree iterator |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
282 | * @see cxTreeIteratorDispose() |
|
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
283 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
284 | CX_EXTERN CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
285 | CxTreeIterator cx_tree_iterator(void *root, bool visit_on_exit, |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
286 | ptrdiff_t loc_children, ptrdiff_t loc_next); |
|
828
88fa3381206d
improve tree iterator struct and add signature for a function that can create an iterator
Mike Becker <universe@uap-core.de>
parents:
827
diff
changeset
|
287 | |
| 845 | 288 | /** |
| 289 | * Creates a breadth-first iterator for a tree with the specified root node. | |
| 290 | * | |
|
1318
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents:
1308
diff
changeset
|
291 | * @note A tree visitor needs to maintain a queue of to-be visited nodes, which |
|
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents:
1308
diff
changeset
|
292 | * is allocated using the cxDefaultAllocator. |
| 859 | 293 | * When the visitor becomes invalid, this memory is automatically released. |
| 294 | * However, if you wish to cancel the iteration before the visitor becomes | |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
295 | * invalid by itself, you MUST call cxTreeIteratorDispose() manually to release |
| 845 | 296 | * the memory. |
| 297 | * | |
| 298 | * @remark The returned iterator does not support cxIteratorFlagRemoval(). | |
| 299 | * | |
| 300 | * @param root the root node | |
| 301 | * @param loc_children offset in the node struct for the children linked list | |
| 302 | * @param loc_next offset in the node struct for the next pointer | |
| 303 | * @return the new tree visitor | |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
304 | * @see cxTreeIteratorDispose() |
| 845 | 305 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
306 | CX_EXTERN CX_NODISCARD |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
307 | CxTreeIterator cx_tree_visitor(void *root, |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
308 | ptrdiff_t loc_children, ptrdiff_t loc_next); |
| 845 | 309 | |
|
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
310 | /** |
|
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
311 | * Base structure that can be used for tree nodes in a #CxTree. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
312 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
313 | struct cx_tree_node_base_s { |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
314 | /** |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
315 | * Pointer to the parent. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
316 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
317 | struct cx_tree_node_base_s *parent; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
318 | /** |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
319 | * Pointer to the first child. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
320 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
321 | struct cx_tree_node_base_s *children; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
322 | /** |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
323 | * Pointer to the last child. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
324 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
325 | struct cx_tree_node_base_s *last_child; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
326 | /** |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
327 | * Pointer to the previous sibling. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
328 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
329 | struct cx_tree_node_base_s *prev; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
330 | /** |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
331 | * Pointer to the next sibling. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
332 | */ |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
333 | struct cx_tree_node_base_s *next; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
334 | }; |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
335 | |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
336 | /** |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
337 | * Structure for holding the base data of a tree. |
|
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
338 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
339 | typedef struct cx_tree_s { |
|
1692
56731bb98508
final docs fixes + add release date to the changelog
Mike Becker <universe@uap-core.de>
parents:
1690
diff
changeset
|
340 | /** Base attributes. */ |
|
1549
72ad8a78378a
changes CxTree structure so that it now inherits CX_COLLECTION_BASE - resolves #629
Mike Becker <universe@uap-core.de>
parents:
1521
diff
changeset
|
341 | CX_COLLECTION_BASE; |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
342 | /** |
|
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
343 | * A pointer to the root node. |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
344 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
345 | * Will be @c NULL when @c size is 0. |
|
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
346 | */ |
|
902
5ed7f634f046
implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents:
901
diff
changeset
|
347 | void *root; |
|
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
348 | |
|
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
349 | /** |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
350 | * The size of the node structure. |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
351 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
352 | size_t node_size; |
|
905
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
353 | |
|
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
354 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
355 | * Offset in the node struct for the parent pointer. |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
356 | */ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
357 | ptrdiff_t loc_parent; |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
358 | |
|
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
359 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
360 | * Offset in the node struct for the children linked list. |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
361 | */ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
362 | ptrdiff_t loc_children; |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
363 | |
|
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
364 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
365 | * Optional offset in the node struct for the pointer to the last child |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
366 | * in the linked list (negative if there is no such pointer). |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
367 | */ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
368 | ptrdiff_t loc_last_child; |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
369 | |
|
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
370 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
371 | * Offset in the node struct for the previous sibling pointer. |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
372 | */ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
373 | ptrdiff_t loc_prev; |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
374 | |
|
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
375 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
376 | * Offset in the node struct for the next sibling pointer. |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
377 | */ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
378 | ptrdiff_t loc_next; |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
379 | |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
380 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
381 | * Offset in the node struct where the payload is located. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
382 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
383 | ptrdiff_t loc_data; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
384 | } CxTree; |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
385 | |
|
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
386 | /** |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
387 | * Macro to roll out the #cx_tree_node_base_s structure with a custom |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
388 | * node type. |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
389 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
390 | * Must be used as the first member in your custom tree struct. |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
391 | * |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
392 | * @param type the data type for the nodes |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
393 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
394 | #define CX_TREE_NODE(type) \ |
|
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
395 | type *parent; \ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
396 | type *children;\ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
397 | type *last_child;\ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
398 | type *prev;\ |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
399 | type *next |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
400 | |
|
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
401 | /** |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
402 | * Macro for specifying the layout of a tree node. |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
403 | * |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
404 | * When your tree uses #CX_TREE_NODE, you can use this |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
405 | * macro in all tree functions that expect the layout parameters |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
406 | * @c loc_parent, @c loc_children, @c loc_last_child, @c loc_prev, |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
407 | * and @c loc_next. |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
408 | * @param struct_name the name of the node structure |
|
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
409 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
410 | #define cx_tree_node_layout(struct_name) \ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
411 | offsetof(struct_name, parent),\ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
412 | offsetof(struct_name, children),\ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
413 | offsetof(struct_name, last_child),\ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
414 | offsetof(struct_name, prev), \ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
415 | offsetof(struct_name, next) |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
416 | |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
417 | /** |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
418 | * Destroys a node and its subtree. |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
419 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
420 | * It is guaranteed that the simple destructor is invoked before |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
421 | * the advanced destructor, starting with the leaf nodes of the subtree. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
422 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
423 | * When this function is invoked on the root node of the tree, it destroys the |
|
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
424 | * tree contents, but - in contrast to #cxTreeFree() - not the tree |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
425 | * structure, leaving an empty tree behind. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
426 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
427 | * @note The destructor function, if any, will @em not be invoked. That means |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
428 | * you will need to free the removed subtree by yourself, eventually. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
429 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
430 | * @attention This function will not free the memory of the nodes with the |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
431 | * tree's allocator, because that is usually done by the advanced destructor |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
432 | * and would therefore result in a double-free. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
433 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
434 | * @param tree the tree |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
435 | * @param node the node being the root of the subtree to remove |
|
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
436 | * @see cxTreeFree() |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
437 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
438 | CX_EXTERN CX_NONNULL |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
439 | void cxTreeDestroySubtree(CxTree *tree, void *node); |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
440 | |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
441 | |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
442 | /** |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
443 | * Destroys the tree contents. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
444 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
445 | * It is guaranteed that the simple destructor is invoked before |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
446 | * the advanced destructor, starting with the leaf nodes of the subtree. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
447 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
448 | * This is a convenience macro for invoking #cxTreeDestroySubtree() on the |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
449 | * root node of the tree. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
450 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
451 | * @attention Be careful when calling this function when no destructor function |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
452 | * is registered that actually frees the memory of nodes. In that case you will |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
453 | * need a reference to the (former) root node of the tree somewhere, or |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
454 | * otherwise you will be leaking memory. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
455 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
456 | * @param tree the tree |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
457 | * @see cxTreeDestroySubtree() |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
458 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
459 | CX_INLINE |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
460 | void cxTreeClear(CxTree *tree) { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
461 | if (tree->root != NULL) { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
462 | cxTreeDestroySubtree(tree, tree->root); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
463 | } |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
464 | } |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
465 | |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
466 | /** |
|
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
467 | * Deallocates the tree structure. |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
468 | * |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
469 | * The destructor functions are invoked for each node, starting with the leaf |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
470 | * nodes. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
471 | * It is guaranteed that for each node the simple destructor is invoked before |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
472 | * the advanced destructor. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
473 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
474 | * @attention This function will only invoke the destructor functions |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
475 | * on the nodes. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
476 | * It will NOT additionally free the nodes with the tree's allocator, because |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
477 | * that would cause a double-free in most scenarios where the advanced |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
478 | * destructor is already freeing the memory. |
|
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
479 | * |
|
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
989
diff
changeset
|
480 | * @param tree the tree to free |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
481 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
482 | CX_EXTERN |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
483 | void cxTreeFree(CxTree *tree); |
|
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
484 | |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
485 | /** |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
486 | * Creates a new tree. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
487 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
488 | * The specified @p allocator will be used for creating the tree struct |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
489 | * @em and the nodes. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
490 | * |
|
1690
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
491 | * When you do not specify an existing @p root, the tree will be created |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
492 | * empty. Additionally, cxFree() is registered as the advanced destructor for |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
493 | * the tree so that all nodes that you will add to the tree are automatically |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
494 | * freed together with the tree. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
495 | * When @p root is not @c NULL, no destructors are registered automatically. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
496 | * |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
497 | * @param allocator the allocator to use |
|
1318
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents:
1308
diff
changeset
|
498 | * (if @c NULL, the cxDefaultAllocator is assumed) |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
499 | * @param node_size the complete size of one node |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
500 | * @param elem_size the size of the payload stored in the node |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
501 | * (@c CX_STORE_POINTERS is also supported) |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
502 | * @param root an optional already existing root node |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
503 | * @param loc_data optional offset in the node struct for the payload |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
504 | * (when negative, cxTreeAddData() is not supported) |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
505 | * @param loc_parent offset in the node struct for the parent pointer |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
506 | * @param loc_children offset in the node struct for the children linked list |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
507 | * @param loc_last_child optional offset in the node struct for the pointer to |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
508 | * the last child in the linked list (negative if there is no such pointer) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
509 | * @param loc_prev optional offset in the node struct for the prev pointer |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
510 | * @param loc_next offset in the node struct for the next pointer |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
511 | * @return the new tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
512 | * @see cxTreeCreate() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
513 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
514 | CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxTreeFree, 1) |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
515 | CxTree *cxTreeCreate(const CxAllocator *allocator, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
516 | size_t node_size, size_t elem_size, void *root, ptrdiff_t loc_data, |
|
1426
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
517 | ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child, |
|
3a89b31f0724
clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
518 | ptrdiff_t loc_prev, ptrdiff_t loc_next); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
519 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
520 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
521 | * Searches the data in the specified subtree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
522 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
523 | * When @p max_depth is zero, the depth is not limited. |
|
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
524 | * The @p subtree_root itself is on depth 1 and its children have depth 2. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
525 | * |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
526 | * @note When @p subtree_root is not @c NULL and not part of the @p tree, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
527 | * the behavior is undefined. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
528 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
529 | * @attention When @p loc_data is not available, this function immediately returns |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
530 | * @c NULL. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
531 | * |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
532 | * @param tree the tree |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
533 | * @param data the data to search for |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
534 | * @param subtree_root the node where to start (@c NULL to start from root) |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
535 | * @param max_depth the maximum search depth |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
536 | * @param use_dfs @c true when depth-first search should be used; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
537 | * @c false when breadth-first search should be used |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
538 | * @return the first matching node, or @c NULL when the data cannot be found |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
539 | * @see cxTreeFind() |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
540 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
541 | CX_EXTERN CX_NONNULL_ARG(1, 2) CX_NODISCARD |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
542 | void *cxTreeFindInSubtree(CxTree *tree, const void *data, void *subtree_root, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
543 | size_t max_depth, bool use_dfs); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
544 | |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
545 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
546 | * Searches the data in the specified tree. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
547 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
548 | * @attention When @p loc_data is not available, this function immediately returns |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
549 | * @c NULL. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
550 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
551 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
552 | * @param data the data to search for |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
553 | * @param use_dfs @c true when depth-first search should be used; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
554 | * @c false when breadth-first search should be used |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
555 | * @return the first matching node, or @c NULL when the data cannot be found |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
556 | * @see cxTreeFindInSubtree() |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
557 | * @see cxTreeFindFast() |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
558 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
559 | CX_INLINE CX_NONNULL CX_NODISCARD |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
560 | void *cxTreeFind(CxTree *tree, const void *data, bool use_dfs) { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
561 | if (tree->root == NULL) return NULL; |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
562 | return cxTreeFindInSubtree(tree, data, tree->root, 0, use_dfs); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
563 | } |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
564 | |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
565 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
566 | * Performs an efficient depth-first search in a branch of the specified tree. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
567 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
568 | * When @p max_depth is zero, the depth is not limited. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
569 | * The @p subtree_root itself is on depth 1 and its children have depth 2. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
570 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
571 | * @note When @p subtree_root is not @c NULL and not part of the @p tree, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
572 | * the behavior is undefined. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
573 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
574 | * @param tree the tree |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
575 | * @param data the data to search for |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
576 | * @param sfunc the search function |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
577 | * @param subtree_root the node where to start (@c NULL to start from root) |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
578 | * @param max_depth the maximum search depth |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
579 | * @return the first matching node, or @c NULL when the data cannot be found |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
580 | * @see cxTreeFindInSubtree() |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
581 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
582 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
583 | void *cxTreeFindFastInSubtree(CxTree *tree, const void *data, |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
584 | cx_tree_search_func sfunc, void *subtree_root, size_t max_depth); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
585 | |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
586 | /** |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
587 | * Performs an efficient depth-first search in the tree. |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
588 | * |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
589 | * @param tree the tree |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
590 | * @param data the data to search for |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
591 | * @param sfunc the search function |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
592 | * @return the first matching node, or @c NULL when the data cannot be found |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
593 | * @see cxTreeFind() |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
594 | */ |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
595 | CX_INLINE CX_NONNULL CX_NODISCARD |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
596 | void *cxTreeFindFast(CxTree *tree, const void *data, cx_tree_search_func sfunc) { |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
597 | return cxTreeFindFastInSubtree(tree, data, sfunc, tree->root, 0); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
598 | } |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
599 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
600 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
601 | * Determines the size of the specified subtree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
602 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
603 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
604 | * @param subtree_root the root node of the subtree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
605 | * @return the number of nodes in the specified subtree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
606 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
607 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
608 | size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
609 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
610 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
611 | * Determines the depth of the specified subtree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
612 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
613 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
614 | * @param subtree_root the root node of the subtree |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
615 | * @return the tree depth including the @p subtree_root |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
616 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
617 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
618 | size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
619 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
620 | /** |
|
1295
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
621 | * Determines the size of the entire tree. |
|
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
622 | * |
|
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
623 | * @param tree the tree |
|
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
624 | * @return the tree size, counting the root as one |
|
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
625 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
626 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
627 | size_t cxTreeSize(CxTree *tree); |
|
1295
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
628 | |
|
b00c6ae1441a
add cxTreeSize() - resolves #624
Mike Becker <universe@uap-core.de>
parents:
1214
diff
changeset
|
629 | /** |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
630 | * Determines the depth of the entire tree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
631 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
632 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
633 | * @return the tree depth, counting the root as one |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
634 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
635 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
636 | size_t cxTreeDepth(CxTree *tree); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
637 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
638 | /** |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
639 | * Creates a depth-first iterator for the specified tree starting in @p node. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
640 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
641 | * If the node is not part of the tree, the behavior is undefined. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
642 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
643 | * @param tree the tree to iterate |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
644 | * @param node the node where to start |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
645 | * @param visit_on_exit true, if the iterator shall visit a node again when |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
646 | * leaving the subtree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
647 | * @return a tree iterator (depth-first) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
648 | * @see cxTreeVisit() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
649 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
650 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
651 | CxTreeIterator cxTreeIterateSubtree(CxTree *tree, void *node, bool visit_on_exit); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
652 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
653 | /** |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
654 | * Creates a breadth-first iterator for the specified tree starting in @p node. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
655 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
656 | * If the node is not part of the tree, the behavior is undefined. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
657 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
658 | * @param tree the tree to iterate |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
659 | * @param node the node where to start |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
660 | * @return a tree visitor (a.k.a. breadth-first iterator) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
661 | * @see cxTreeIterate() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
662 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
663 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
664 | CxTreeIterator cxTreeVisitSubtree(CxTree *tree, void *node); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
665 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
666 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
667 | * Creates a depth-first iterator for the specified tree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
668 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
669 | * @param tree the tree to iterate |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
670 | * @param visit_on_exit true, if the iterator shall visit a node again when |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
671 | * leaving the subtree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
672 | * @return a tree iterator (depth-first) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
673 | * @see cxTreeVisit() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
674 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
675 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
676 | CxTreeIterator cxTreeIterate(CxTree *tree, bool visit_on_exit); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
677 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
678 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
679 | * Creates a breadth-first iterator for the specified tree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
680 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
681 | * @param tree the tree to iterate |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
682 | * @return a tree visitor (a.k.a. breadth-first iterator) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
683 | * @see cxTreeIterate() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
684 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
685 | CX_EXTERN CX_NONNULL CX_NODISCARD |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
686 | CxTreeIterator cxTreeVisit(CxTree *tree); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
687 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
688 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
689 | * Sets the (new) parent of the specified child. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
690 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
691 | * If the @p child is not already a member of the tree, this function behaves |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
692 | * as #cxTreeAddNode(). |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
693 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
694 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
695 | * @param parent the (new) parent of the child |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
696 | * @param child the node to add |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
697 | * @see cxTreeAddNode() |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
698 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
699 | CX_EXTERN CX_NONNULL |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
700 | void cxTreeSetParent(CxTree *tree, void *parent, void *child); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
701 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
702 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
703 | * Adds a new node to the tree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
704 | * |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
705 | * If the @p child is already a member of the tree, the behavior is undefined. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
706 | * Use #cxTreeSetParent() if you want to move a subtree to another location. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
707 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
708 | * @attention The node may be externally created, but MUST obey the same rules |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
709 | * as if it was created by the tree itself with #cxTreeAddData() (e.g., use |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
710 | * the tree's allocator). |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
711 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
712 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
713 | * @param parent the parent of the node to add |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
714 | * @param child the node to add |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
715 | * @see cxTreeSetParent() |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
716 | * @see cxTreeAddData() |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
717 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
718 | CX_EXTERN CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
719 | void cxTreeAddNode(CxTree *tree, void *parent, void *child); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
720 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
721 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
722 | * Creates a new node and adds it to the tree. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
723 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
724 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
725 | * @param parent the parent node of the new node |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
726 | * @param data the data that will be submitted to the create function |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
727 | * @return the added node or @c NULL when the allocation failed |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
728 | * @see cxTreeAdd() |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
729 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
730 | CX_EXTERN CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
731 | void *cxTreeAddData(CxTree *tree, void *parent, const void *data); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
732 | |
|
1690
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
733 | /** |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
734 | * Creates a new node and adds it to the tree. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
735 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
736 | * @param tree the tree |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
737 | * @param parent the parent node of the new node |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
738 | * @return the added node or @c NULL when the allocation failed |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
739 | */ |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
740 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
741 | void *cxTreeCreateNode(CxTree *tree, void *parent); |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
742 | |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
743 | /** |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
744 | * Creates a new root node or returns the existing root node. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
745 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
746 | * @param tree the tree |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
747 | * @return the new root node, the existing root node, or @c NULL when the allocation failed |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
748 | * @see cxTreeCreateRootData() |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
749 | */ |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
750 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
751 | void *cxTreeCreateRoot(CxTree *tree); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
752 | |
|
1690
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
753 | /** |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
754 | * Creates a new root node or uses the existing root node and writes the specified data to that node. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
755 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
756 | * @note This function immediately returns @c NULL when @c loc_data was not initialized with a positive value. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
757 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
758 | * @param tree the tree |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
759 | * @param data the data for the root node |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
760 | * @return the new root node, the existing root node, |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
761 | * or @c NULL when the allocation failed or the data location is not known |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
762 | * @see cxTreeCreateRoot() |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
763 | */ |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
764 | CX_EXTERN CX_NODISCARD CX_NONNULL |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
765 | void *cxTreeCreateRootData(CxTree *tree, const void *data); |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
766 | |
|
1690
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
767 | /** |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
768 | * Exchanges the root of the tree. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
769 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
770 | * @attention The old tree nodes might need to be deallocated by the caller. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
771 | * On the other hand, when the tree has destructors registered, keep in mind |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
772 | * that they will be applied to the new tree. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
773 | * In particular, using cxTreeCreate() with a @c NULL root and setting the |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
774 | * root with this function is @em not equivalent to creating the tree with |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
775 | * a reference to an existing root because trees created without a root will |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
776 | * have destructors registered. |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
777 | * |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
778 | * @param tree the tree |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
779 | * @param new_root the new root node |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
780 | * @return the old root node (or @c NULL when the tree was empty) |
|
7d41291b3095
complete tree.c testing
Mike Becker <universe@uap-core.de>
parents:
1681
diff
changeset
|
781 | */ |
|
1681
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
782 | CX_EXTERN CX_NONNULL_ARG(1) CX_NODISCARD |
|
56e76fbac167
rework of the entire tree API - resolves #772
Mike Becker <universe@uap-core.de>
parents:
1675
diff
changeset
|
783 | void *cxTreeSetRoot(CxTree *tree, void *new_root); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
784 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
785 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
786 | * A function that is invoked when a node needs to be re-linked to a new parent. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
787 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
788 | * When a node is re-linked, sometimes the contents need to be updated. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
789 | * This callback is invoked by #cxTreeRemoveNode() and #cxTreeDestroyNode() |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
790 | * so that those updates can be applied when re-linking the children of the |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
791 | * removed node. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
792 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
793 | * @param node the affected node |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
794 | * @param old_parent the old parent of the node |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
795 | * @param new_parent the new parent of the node |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
796 | */ |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
797 | typedef void (*cx_tree_relink_func)( |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
798 | void *node, |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
799 | const void *old_parent, |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
800 | const void *new_parent |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
801 | ); |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
802 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
803 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
804 | * Removes a node and re-links its children to its former parent. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
805 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
806 | * If the node is not part of the tree, the behavior is undefined. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
807 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
808 | * @note The destructor function, if any, will @em not be invoked. That means |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
809 | * you will need to free the removed node by yourself, eventually. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
810 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
811 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
812 | * @param node the node to remove (must not be the root node) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
813 | * @param relink_func optional callback to update the content of each re-linked |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
814 | * node |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
815 | * @return zero on success, non-zero if @p node is the root node of the tree |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
816 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
817 | CX_EXTERN CX_NONNULL_ARG(1, 2) |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
818 | int cxTreeRemoveNode(CxTree *tree, void *node, cx_tree_relink_func relink_func); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
819 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
820 | /** |
|
1424
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents:
1319
diff
changeset
|
821 | * Removes a node and its subtree from the tree. |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
822 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
823 | * If the node is not part of the tree, the behavior is undefined. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
824 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
825 | * @note The destructor function, if any, will @em not be invoked. That means |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
826 | * you will need to free the removed subtree by yourself, eventually. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
827 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
828 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
829 | * @param node the node to remove |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
830 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
831 | CX_EXTERN CX_NONNULL |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
832 | void cxTreeRemoveSubtree(CxTree *tree, void *node); |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
833 | |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
834 | /** |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
835 | * Destroys a node and re-links its children to its former parent. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
836 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
837 | * If the node is not part of the tree, the behavior is undefined. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
838 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
839 | * It is guaranteed that the simple destructor is invoked before |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
840 | * the advanced destructor. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
841 | * |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
842 | * @attention This function will not free the memory of the node with the |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
843 | * tree's allocator, because that is usually done by the advanced destructor |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
844 | * and would therefore result in a double-free. |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
845 | * |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
846 | * @param tree the tree |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
847 | * @param node the node to destroy (must not be the root node) |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
848 | * @param relink_func optional callback to update the content of each re-linked |
|
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
849 | * node |
|
1108
c3bde8ff1c0b
refine docs for tree.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
850 | * @return zero on success, non-zero if @p node is the root node of the tree |
|
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
851 | */ |
|
1675
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
852 | CX_EXTERN CX_NONNULL_ARG(1, 2) |
|
36c0fb2b60b2
overhaul all attributes
Mike Becker <universe@uap-core.de>
parents:
1549
diff
changeset
|
853 | int cxTreeDestroyNode(CxTree *tree, void *node, cx_tree_relink_func relink_func); |
|
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
854 | |
|
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
855 | #endif //UCX_TREE_H |