Sat, 23 Nov 2024 15:15:09 +0100
automatically disable szmul builtin when testing with coverage
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 | /** |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | * \file tree.h |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | * \brief Interface for tree implementations. |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | * \author Mike Becker |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | * \author Olaf Wintermann |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | * \copyright 2-Clause BSD License |
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 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | #ifdef __cplusplus |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | extern "C" { |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | #endif |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
47 | /** |
845 | 48 | * A depth-first tree iterator. |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
49 | * |
859 | 50 | * This iterator is not position-aware in a strict sense, as it does not assume |
51 | * a particular order of elements in the tree. However, the iterator keeps track | |
52 | * of the number of nodes it has passed in a counter variable. | |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
53 | * Each node, regardless of the number of passes, is counted only once. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
54 | * |
859 | 55 | * @note Objects that are pointed to by an iterator are mutable through that |
56 | * iterator. However, if the | |
57 | * underlying data structure is mutated by other means than this iterator (e.g. | |
58 | * elements added or removed), the iterator becomes invalid (regardless of what | |
59 | * cxIteratorValid() returns). | |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
60 | * |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
61 | * @see CxIterator |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
62 | */ |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
63 | typedef struct cx_tree_iterator_s { |
854
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
64 | /** |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
65 | * Base members. |
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 | CX_ITERATOR_BASE; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
68 | /** |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
69 | * Indicates whether the subtree below the current node shall be skipped. |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
70 | */ |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
71 | bool skip; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
72 | /** |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
73 | * Set to true, when the iterator shall visit a node again |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
74 | * when all it's children have been processed. |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
75 | */ |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
76 | bool visit_on_exit; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
77 | /** |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
78 | * True, if this iterator is currently leaving the node. |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
79 | */ |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
80 | bool exiting; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
81 | /** |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
82 | * Offset in the node struct for the children linked list. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
83 | */ |
845 | 84 | ptrdiff_t loc_children; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
85 | /** |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
86 | * Offset in the node struct for the next pointer. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
87 | */ |
845 | 88 | ptrdiff_t loc_next; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
89 | /** |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
90 | * The total number of distinct nodes that have been passed so far. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
91 | */ |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
92 | size_t counter; |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
93 | /** |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
94 | * The currently observed node. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
95 | * |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
96 | * This is the same what cxIteratorCurrent() would return. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
97 | */ |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
98 | void *node; |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
99 | /** |
840
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
835
diff
changeset
|
100 | * Stores a copy of the next pointer of the visited node. |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
835
diff
changeset
|
101 | * Allows freeing a node on exit without corrupting the iteration. |
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
835
diff
changeset
|
102 | */ |
853
d4baf4dd55c3
simplify iterator structures
Mike Becker <universe@uap-core.de>
parents:
848
diff
changeset
|
103 | void *node_next; |
840
4f02995ce44e
allow freeing tree nodes on exit - fixes #377
Mike Becker <universe@uap-core.de>
parents:
835
diff
changeset
|
104 | /** |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
105 | * Internal stack. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
106 | * Will be automatically freed once the iterator becomes invalid. |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
107 | * |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
108 | * If you want to discard the iterator before, you need to manually |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
109 | * call cxTreeIteratorDispose(). |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
110 | */ |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
111 | void **stack; |
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
|
112 | /** |
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
|
113 | * Internal capacity of the stack. |
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
|
114 | */ |
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
|
115 | size_t stack_capacity; |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
116 | union { |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
117 | /** |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
118 | * Internal stack size. |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
119 | */ |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
120 | size_t stack_size; |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
121 | /** |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
122 | * The current depth in the tree. |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
123 | */ |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
124 | size_t depth; |
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
125 | }; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
126 | } CxTreeIterator; |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
127 | |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
128 | /** |
845 | 129 | * An element in a visitor queue. |
130 | */ | |
131 | struct cx_tree_visitor_queue_s { | |
132 | /** | |
133 | * The tree node to visit. | |
134 | */ | |
135 | void *node; | |
136 | /** | |
137 | * The depth of the node. | |
138 | */ | |
139 | size_t depth; | |
140 | /** | |
141 | * The next element in the queue or \c NULL. | |
142 | */ | |
143 | struct cx_tree_visitor_queue_s *next; | |
144 | }; | |
145 | ||
146 | /** | |
147 | * A breadth-first tree iterator. | |
148 | * | |
859 | 149 | * This iterator needs to maintain a visitor queue that will be automatically |
150 | * freed once the iterator becomes invalid. | |
151 | * If you want to discard the iterator before, you MUST manually call | |
152 | * cxTreeVisitorDispose(). | |
845 | 153 | * |
859 | 154 | * This iterator is not position-aware in a strict sense, as it does not assume |
155 | * a particular order of elements in the tree. However, the iterator keeps track | |
156 | * of the number of nodes it has passed in a counter variable. | |
845 | 157 | * Each node, regardless of the number of passes, is counted only once. |
158 | * | |
859 | 159 | * @note Objects that are pointed to by an iterator are mutable through that |
160 | * iterator. However, if the | |
161 | * underlying data structure is mutated by other means than this iterator (e.g. | |
162 | * elements added or removed), the iterator becomes invalid (regardless of what | |
163 | * cxIteratorValid() returns). | |
845 | 164 | * |
165 | * @see CxIterator | |
166 | */ | |
167 | typedef struct cx_tree_visitor_s { | |
854
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
168 | /** |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
169 | * Base members. |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
170 | */ |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
171 | CX_ITERATOR_BASE; |
845 | 172 | /** |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
173 | * Indicates whether the subtree below the current node shall be skipped. |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
174 | */ |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
175 | bool skip; |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
176 | /** |
845 | 177 | * Offset in the node struct for the children linked list. |
178 | */ | |
179 | ptrdiff_t loc_children; | |
180 | /** | |
181 | * Offset in the node struct for the next pointer. | |
182 | */ | |
183 | ptrdiff_t loc_next; | |
184 | /** | |
185 | * The total number of distinct nodes that have been passed so far. | |
186 | */ | |
187 | size_t counter; | |
188 | /** | |
189 | * The currently observed node. | |
190 | * | |
191 | * This is the same what cxIteratorCurrent() would return. | |
192 | */ | |
193 | void *node; | |
194 | /** | |
195 | * The current depth in the tree. | |
196 | */ | |
197 | size_t depth; | |
198 | /** | |
199 | * The next element in the visitor queue. | |
200 | */ | |
201 | struct cx_tree_visitor_queue_s *queue_next; | |
202 | /** | |
203 | * The last element in the visitor queue. | |
204 | */ | |
205 | struct cx_tree_visitor_queue_s *queue_last; | |
206 | } CxTreeVisitor; | |
207 | ||
208 | /** | |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
209 | * 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
|
210 | * @param iter the iterator |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
211 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
212 | cx_attr_nonnull |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
213 | static inline void cxTreeIteratorDispose(CxTreeIterator *iter) { |
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
214 | free(iter->stack); |
835
13068743197f
set tree iterator stack pointer to NULL on dispose to avoid accidental double-frees
Mike Becker <universe@uap-core.de>
parents:
833
diff
changeset
|
215 | iter->stack = NULL; |
827
13b40a598d16
first draft of a tree iterator
Mike Becker <universe@uap-core.de>
parents:
826
diff
changeset
|
216 | } |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | |
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
218 | /** |
845 | 219 | * Releases internal memory of the given tree visitor. |
220 | * @param visitor the visitor | |
221 | */ | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
222 | cx_attr_nonnull |
845 | 223 | static inline void cxTreeVisitorDispose(CxTreeVisitor *visitor) { |
224 | struct cx_tree_visitor_queue_s *q = visitor->queue_next; | |
225 | while (q != NULL) { | |
226 | struct cx_tree_visitor_queue_s *next = q->next; | |
227 | free(q); | |
228 | q = next; | |
229 | } | |
230 | } | |
231 | ||
232 | /** | |
848
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
233 | * 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
|
234 | * also continues the current loop. |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
235 | * |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
236 | * @param iterator the iterator |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
237 | */ |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
238 | #define cxTreeIteratorContinue(iterator) (iterator).skip = true; continue |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
239 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
240 | /** |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
241 | * Advises the visitor 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
|
242 | * also continues the current loop. |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
243 | * |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
244 | * @param visitor the visitor |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
245 | */ |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
246 | #define cxTreeVisitorContinue(visitor) cxTreeIteratorContinue(visitor) |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
247 | |
6456036bbb37
implement tree continue - fixes #376
Mike Becker <universe@uap-core.de>
parents:
845
diff
changeset
|
248 | /** |
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
249 | * Links a node to a (new) parent. |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
250 | * |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
251 | * If the node has already a parent, it is unlinked, first. |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
252 | * 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
|
253 | * of all currently existing children. |
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
254 | * |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
255 | * @param parent the parent node |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
256 | * @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
|
257 | * @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
|
258 | * @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
|
259 | * @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
|
260 | * 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
|
261 | * @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
|
262 | * @param loc_next offset in the node struct for the next pointer |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
263 | * @see cx_tree_unlink() |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
264 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
265 | cx_attr_nonnull |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
266 | void cx_tree_link( |
988
15b3ca7ee33f
make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
267 | void *parent, |
15b3ca7ee33f
make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents:
985
diff
changeset
|
268 | void *node, |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | ptrdiff_t loc_parent, |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | ptrdiff_t loc_children, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
271 | ptrdiff_t loc_last_child, |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | ptrdiff_t loc_prev, |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | ptrdiff_t loc_next |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | ); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | |
822
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
276 | /** |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
277 | * Unlinks a node from its parent. |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
278 | * |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
279 | * 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
|
280 | * |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
281 | * @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
|
282 | * @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
|
283 | * @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
|
284 | * @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
|
285 | * 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
|
286 | * @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
|
287 | * @param loc_next offset in the node struct for the next pointer |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
288 | * @see cx_tree_link() |
e2243453127f
add code documentation for tree functions
Mike Becker <universe@uap-core.de>
parents:
816
diff
changeset
|
289 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
290 | cx_attr_nonnull |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | void cx_tree_unlink( |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | void *node, |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | ptrdiff_t loc_parent, |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | ptrdiff_t loc_children, |
862
387414a7afd8
change cx_tree_link() from prepending to appending children - fixes #391
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
295 | ptrdiff_t loc_last_child, |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | ptrdiff_t loc_prev, |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | ptrdiff_t loc_next |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
298 | ); |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | |
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
300 | /** |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
301 | * 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
|
302 | */ |
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
303 | #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
|
304 | |
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
305 | /** |
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
306 | * Function pointer for a search function. |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
307 | * |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
308 | * A function of this kind shall check if the specified \p node |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
309 | * contains the given \p data or if one of the children might contain |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
310 | * the data. |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
311 | * |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
312 | * 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
|
313 | * 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
|
314 | * 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
|
315 | * 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
|
316 | * |
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
317 | * For example if a tree stores file path information, a node that is |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
318 | * describing a parent directory of a filename that is searched, shall |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
319 | * 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
|
320 | * 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
|
321 | * prefix of the searched filename, the function would return -1 to indicate |
859 | 322 | * 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
|
323 | * |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
324 | * @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
|
325 | * @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
|
326 | * |
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
327 | * @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
|
328 | * positive if one of the children might contain the data, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
329 | * 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
|
330 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
331 | cx_attr_nonnull |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
332 | typedef int (*cx_tree_search_data_func)(const void *node, const void *data); |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
333 | |
823
f4faa7f73cb8
declare cx_tree_search_func function pointer
Mike Becker <universe@uap-core.de>
parents:
822
diff
changeset
|
334 | |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
335 | /** |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
336 | * Function pointer for a search function. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
337 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
338 | * A function of this kind shall check if the specified \p node |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
339 | * contains the same \p data as \p new_node or if one of the children might |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
340 | * contain the data. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
341 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
342 | * The function should use the returned integer to indicate how close the |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
343 | * 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
|
344 | * 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
|
345 | * measure for the distance to an exact match. |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
346 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
347 | * For example if a tree stores file path information, a node that is |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
348 | * describing a parent directory of a filename that is searched, shall |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
349 | * return a positive number to indicate that a child node might contain the |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
350 | * searched item. On the other hand, if the node denotes a path that is not a |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
351 | * prefix of the searched filename, the function would return -1 to indicate |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
352 | * that the search does not need to be continued in that branch. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
353 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
354 | * @param node the node that is currently investigated |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
355 | * @param new_node a new node with the information which is searched |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
356 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
357 | * @return 0 if \p node contains the same data as \p new_node, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
358 | * positive if one of the children might contain the data, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
359 | * negative if neither the node, nor the children contains the data |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
360 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
361 | cx_attr_nonnull |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
362 | typedef int (*cx_tree_search_func)(const void *node, const void *new_node); |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
363 | |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
364 | /** |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
365 | * Searches for data in a tree. |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
366 | * |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
367 | * When the data cannot be found exactly, the search function might return a |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
368 | * closest result which might be a good starting point for adding a new node |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
369 | * to the tree (see also #cx_tree_add()). |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
370 | * |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
371 | * Depending on the tree structure it is not necessarily guaranteed that the |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
372 | * "closest" match is uniquely defined. This function will search for a node |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
373 | * with the best match according to the \p sfunc (meaning: the return value of |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
374 | * \p sfunc which is closest to zero). If that is also ambiguous, an arbitrary |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
375 | * node matching the criteria is returned. |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
376 | * |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
377 | * @param root the root node |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
378 | * @param 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
|
379 | * @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
|
380 | * @param sfunc the search function |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
381 | * @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
|
382 | * @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
|
383 | * @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
|
384 | * @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
|
385 | * 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
|
386 | * 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
|
387 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
388 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
389 | cx_attr_access_w(5) |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
390 | int cx_tree_search_data( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
391 | const void *root, |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
392 | size_t depth, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
393 | const void *data, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
394 | cx_tree_search_data_func sfunc, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
395 | void **result, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
396 | ptrdiff_t loc_children, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
397 | ptrdiff_t loc_next |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
398 | ); |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
399 | |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
400 | /** |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
401 | * Searches for a node in a tree. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
402 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
403 | * When no node with the same data can be found, the search function might |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
404 | * return a closest result which might be a good starting point for adding the |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
405 | * new node to the tree (see also #cx_tree_add()). |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
406 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
407 | * Depending on the tree structure it is not necessarily guaranteed that the |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
408 | * "closest" match is uniquely defined. This function will search for a node |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
409 | * with the best match according to the \p sfunc (meaning: the return value of |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
410 | * \p sfunc which is closest to zero). If that is also ambiguous, an arbitrary |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
411 | * node matching the criteria is returned. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
412 | * |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
413 | * @param root the root node |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
414 | * @param depth the maximum depth (zero=indefinite, one=just root) |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
415 | * @param node the node to search for |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
416 | * @param sfunc the search function |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
417 | * @param result where the result shall be stored |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
418 | * @param loc_children offset in the node struct for the children linked list |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
419 | * @param loc_next offset in the node struct for the next pointer |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
420 | * @return zero if the node was found exactly, positive if a node was found that |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
421 | * could contain the node (but doesn't right now), negative if the tree does not |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
422 | * contain any node that might be related to the searched data |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
423 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
424 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
425 | cx_attr_access_w(5) |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
426 | int cx_tree_search( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
427 | const void *root, |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
428 | size_t depth, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
429 | const void *node, |
826
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
430 | cx_tree_search_func sfunc, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
431 | void **result, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
432 | ptrdiff_t loc_children, |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
433 | ptrdiff_t loc_next |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
434 | ); |
21840975d541
add cx_tree_search() - relates to #165
Mike Becker <universe@uap-core.de>
parents:
824
diff
changeset
|
435 | |
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
|
436 | /** |
845 | 437 | * 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
|
438 | * |
859 | 439 | * @note A tree iterator needs to maintain a stack of visited nodes, which is |
440 | * allocated using stdlib malloc(). | |
441 | * When the iterator becomes invalid, this memory is automatically released. | |
442 | * However, if you wish to cancel the iteration before the iterator becomes | |
443 | * 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
|
444 | * 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
|
445 | * |
845 | 446 | * @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
|
447 | * |
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
|
448 | * @param root the root node |
859 | 449 | * @param visit_on_exit set to true, when the iterator shall visit a node again |
450 | * 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
|
451 | * @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
|
452 | * @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
|
453 | * @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
|
454 | * @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
|
455 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
456 | cx_attr_nodiscard |
830
c4dae6fe6d5b
commit complicated stuff before simplifying it
Mike Becker <universe@uap-core.de>
parents:
828
diff
changeset
|
457 | CxTreeIterator cx_tree_iterator( |
c4dae6fe6d5b
commit complicated stuff before simplifying it
Mike Becker <universe@uap-core.de>
parents:
828
diff
changeset
|
458 | void *root, |
833
5c926801f052
vastly simplify tree iterators and add test for creating them
Mike Becker <universe@uap-core.de>
parents:
830
diff
changeset
|
459 | bool visit_on_exit, |
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
|
460 | ptrdiff_t loc_children, |
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
|
461 | ptrdiff_t loc_next |
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
|
462 | ); |
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
|
463 | |
845 | 464 | /** |
465 | * Creates a breadth-first iterator for a tree with the specified root node. | |
466 | * | |
859 | 467 | * @note A tree visitor needs to maintain a queue of to be visited nodes, which |
468 | * is allocated using stdlib malloc(). | |
469 | * When the visitor becomes invalid, this memory is automatically released. | |
470 | * However, if you wish to cancel the iteration before the visitor becomes | |
471 | * invalid by itself, you MUST call cxTreeVisitorDispose() manually to release | |
845 | 472 | * the memory. |
473 | * | |
474 | * @remark The returned iterator does not support cxIteratorFlagRemoval(). | |
475 | * | |
476 | * @param root the root node | |
477 | * @param loc_children offset in the node struct for the children linked list | |
478 | * @param loc_next offset in the node struct for the next pointer | |
479 | * @return the new tree visitor | |
480 | * @see cxTreeVisitorDispose() | |
481 | */ | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
482 | cx_attr_nodiscard |
845 | 483 | CxTreeVisitor cx_tree_visitor( |
484 | void *root, | |
485 | ptrdiff_t loc_children, | |
486 | ptrdiff_t loc_next | |
487 | ); | |
488 | ||
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
489 | /** |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
490 | * Describes a function that creates a tree node from the specified data. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
491 | * The first argument points to the data the node shall contain and |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
492 | * the second argument may be used for additional data (e.g. an allocator). |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
493 | * Functions of this type shall either return a new pointer to a newly |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
494 | * created node or \c NULL when allocation fails. |
865
4b325b639117
fix return type of cx_tree_node_create_func
Mike Becker <universe@uap-core.de>
parents:
864
diff
changeset
|
495 | * |
4b325b639117
fix return type of cx_tree_node_create_func
Mike Becker <universe@uap-core.de>
parents:
864
diff
changeset
|
496 | * \note the function may leave the node pointers in the struct uninitialized. |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
497 | * The caller is responsible to set them according to the intended use case. |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
498 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
499 | cx_attr_nonnull_arg(1) |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
500 | typedef void *(*cx_tree_node_create_func)(const void *, void *); |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
501 | |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
502 | /** |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
503 | * The local search depth for a new subtree when adding multiple elements. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
504 | * The default value is 3. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
505 | * This variable is used by #cx_tree_add_array() and #cx_tree_add_iter() to |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
506 | * implement optimized insertion of multiple elements into a tree. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
507 | */ |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
508 | extern unsigned int cx_tree_add_look_around_depth; |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
509 | |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
510 | /** |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
511 | * Adds multiple elements efficiently to a tree. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
512 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
513 | * Once an element cannot be added to the tree, this function returns, leaving |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
514 | * the iterator in a valid state pointing to the element that could not be |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
515 | * added. |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
516 | * Also, the pointer of the created node will be stored to \p failed. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
517 | * The integer returned by this function denotes the number of elements obtained |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
518 | * from the \p iter that have been successfully processed. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
519 | * When all elements could be processed, a \c NULL pointer will be written to |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
520 | * \p failed. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
521 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
522 | * The advantage of this function compared to multiple invocations of |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
523 | * #cx_tree_add() is that the search for the insert locations is not always |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
524 | * started from the root node. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
525 | * Instead, the function checks #cx_tree_add_look_around_depth many parent nodes |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
526 | * of the current insert location before starting from the root node again. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
527 | * When the variable is set to zero, only the last found location is checked |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
528 | * again. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
529 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
530 | * Refer to the documentation of #cx_tree_add() for more details. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
531 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
532 | * @param iter a pointer to an arbitrary iterator |
893
0a2b328f5b91
add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
533 | * @param num the maximum number of elements to obtain from the iterator |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
534 | * @param sfunc a search function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
535 | * @param cfunc a node creation function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
536 | * @param cdata optional additional data |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
537 | * @param root the root node of the tree |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
538 | * @param failed location where the pointer to a failed node shall be stored |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
539 | * @param loc_parent offset in the node struct for the parent pointer |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
540 | * @param loc_children offset in the node struct for the children linked list |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
541 | * @param loc_last_child optional offset in the node struct for the pointer to |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
542 | * 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
|
543 | * @param loc_prev optional offset in the node struct for the prev pointer |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
544 | * @param loc_next offset in the node struct for the next pointer |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
545 | * @return the number of nodes created and added |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
546 | * @see cx_tree_add() |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
547 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
548 | cx_attr_nonnull_arg(1, 3, 4, 6, 7) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
549 | cx_attr_access_w(6) |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
550 | size_t cx_tree_add_iter( |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
551 | struct cx_iterator_base_s *iter, |
893
0a2b328f5b91
add bounding parameter to cx_tree_add_iter()
Mike Becker <universe@uap-core.de>
parents:
890
diff
changeset
|
552 | size_t num, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
553 | cx_tree_search_func sfunc, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
554 | cx_tree_node_create_func cfunc, |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
555 | void *cdata, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
556 | void **failed, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
557 | void *root, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
558 | ptrdiff_t loc_parent, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
559 | ptrdiff_t loc_children, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
560 | ptrdiff_t loc_last_child, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
561 | ptrdiff_t loc_prev, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
562 | ptrdiff_t loc_next |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
563 | ); |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
564 | |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
565 | /** |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
566 | * Adds multiple elements efficiently to a tree. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
567 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
568 | * Once an element cannot be added to the tree, this function returns, storing |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
569 | * the pointer of the created node to \p failed. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
570 | * The integer returned by this function denotes the number of elements from |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
571 | * the \p src array that have been successfully processed. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
572 | * When all elements could be processed, a \c NULL pointer will be written to |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
573 | * \p failed. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
574 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
575 | * The advantage of this function compared to multiple invocations of |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
576 | * #cx_tree_add() is that the search for the insert locations is not always |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
577 | * started from the root node. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
578 | * Instead, the function checks #cx_tree_add_look_around_depth many parent nodes |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
579 | * of the current insert location before starting from the root node again. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
580 | * When the variable is set to zero, only the last found location is checked |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
581 | * again. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
582 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
583 | * Refer to the documentation of #cx_tree_add() for more details. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
584 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
585 | * @param src a pointer to the source data array |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
586 | * @param num the number of elements in the \p src array |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
587 | * @param elem_size the size of each element in the \p src array |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
588 | * @param sfunc a search function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
589 | * @param cfunc a node creation function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
590 | * @param cdata optional additional data |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
591 | * @param failed location where the pointer to a failed node shall be stored |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
592 | * @param root the root node of the tree |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
593 | * @param loc_parent offset in the node struct for the parent pointer |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
594 | * @param loc_children offset in the node struct for the children linked list |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
595 | * @param loc_last_child optional offset in the node struct for the pointer to |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
596 | * 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
|
597 | * @param loc_prev optional offset in the node struct for the prev pointer |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
598 | * @param loc_next offset in the node struct for the next pointer |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
599 | * @return the number of array elements successfully processed |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
600 | * @see cx_tree_add() |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
601 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
602 | cx_attr_nonnull_arg(1, 4, 5, 7, 8) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
603 | cx_attr_access_w(7) |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
604 | size_t cx_tree_add_array( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
605 | const void *src, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
606 | size_t num, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
607 | size_t elem_size, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
608 | cx_tree_search_func sfunc, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
609 | cx_tree_node_create_func cfunc, |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
610 | void *cdata, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
611 | void **failed, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
612 | void *root, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
613 | ptrdiff_t loc_parent, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
614 | ptrdiff_t loc_children, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
615 | ptrdiff_t loc_last_child, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
616 | ptrdiff_t loc_prev, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
617 | ptrdiff_t loc_next |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
618 | ); |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
619 | |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
620 | /** |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
621 | * Adds data to a tree. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
622 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
623 | * An adequate location where to add the new tree node is searched with the |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
624 | * specified \p sfunc. |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
625 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
626 | * When a location is found, the \p cfunc will be invoked with \p cdata. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
627 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
628 | * The node returned by \p cfunc will be linked into the tree. |
867
471c714d5b6f
cx_tree_add() fix missing spec for adding duplicates
Mike Becker <universe@uap-core.de>
parents:
865
diff
changeset
|
629 | * When \p sfunc returned a positive integer, the new node will be linked as a |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
630 | * child. The other children (now siblings of the new node) are then checked |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
631 | * with \p sfunc, whether they could be children of the new node and re-linked |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
632 | * accordingly. |
867
471c714d5b6f
cx_tree_add() fix missing spec for adding duplicates
Mike Becker <universe@uap-core.de>
parents:
865
diff
changeset
|
633 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
634 | * When \p sfunc returned zero and the found node has a parent, the new |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
635 | * node will be added as sibling - otherwise, the new node will be added |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
636 | * as a child. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
637 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
638 | * When \p sfunc returned a negative value, the new node will not be added to |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
639 | * the tree and this function returns a non-zero value. |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
640 | * The caller should check if \p cnode contains a node pointer and deal with the |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
641 | * node that could not be added. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
642 | * |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
643 | * This function also returns a non-zero value when \p cfunc tries to allocate |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
644 | * a new node but fails to do so. In that case, the pointer stored to \p cnode |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
645 | * will be \c NULL. |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
646 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
647 | * Multiple elements can be added more efficiently with |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
648 | * #cx_tree_add_array() or #cx_tree_add_iter(). |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
649 | * |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
650 | * @param src a pointer to the data |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
651 | * @param sfunc a search function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
652 | * @param cfunc a node creation function |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
653 | * @param cdata optional additional data |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
654 | * @param cnode the location where a pointer to the new node is stored |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
655 | * @param root the root node of the tree |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
656 | * @param loc_parent offset in the node struct for the parent pointer |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
657 | * @param loc_children offset in the node struct for the children linked list |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
658 | * @param loc_last_child optional offset in the node struct for the pointer to |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
659 | * 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
|
660 | * @param loc_prev optional offset in the node struct for the prev pointer |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
661 | * @param loc_next offset in the node struct for the next pointer |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
662 | * @return zero when a new node was created and added to the tree, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
663 | * non-zero otherwise |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
664 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
665 | cx_attr_nonnull_arg(1, 2, 3, 5, 6) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
666 | cx_attr_access_w(5) |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
667 | int cx_tree_add( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
871
diff
changeset
|
668 | const void *src, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
669 | cx_tree_search_func sfunc, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
670 | cx_tree_node_create_func cfunc, |
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
671 | void *cdata, |
871
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
672 | void **cnode, |
e29c1f96646d
rework cx_tree_add() API to allow insertion of edge nodes
Mike Becker <universe@uap-core.de>
parents:
867
diff
changeset
|
673 | void *root, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
674 | ptrdiff_t loc_parent, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
675 | ptrdiff_t loc_children, |
864
7d3061f212cb
complete specification for tree_add functions
Mike Becker <universe@uap-core.de>
parents:
863
diff
changeset
|
676 | ptrdiff_t loc_last_child, |
860
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
677 | ptrdiff_t loc_prev, |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
678 | ptrdiff_t loc_next |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
679 | ); |
558ed4c6abd0
add prototypes for cx_tree_add() family of functions
Mike Becker <universe@uap-core.de>
parents:
859
diff
changeset
|
680 | |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
681 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
682 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
683 | * Tree class type. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
684 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
685 | typedef struct cx_tree_class_s cx_tree_class; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
686 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
687 | /** |
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
688 | * 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
|
689 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
690 | 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
|
691 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
692 | * Pointer to the parent. |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
693 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
694 | 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
|
695 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
696 | * 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
|
697 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
698 | 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
|
699 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
700 | * 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
|
701 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
702 | 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
|
703 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
704 | * 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
|
705 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
706 | 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
|
707 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
708 | * 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
|
709 | */ |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
710 | 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
|
711 | }; |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
712 | |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
713 | /** |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
714 | * 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
|
715 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
716 | struct cx_tree_s { |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
717 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
718 | * The tree class definition. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
719 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
720 | const cx_tree_class *cl; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
721 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
722 | /** |
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
723 | * Allocator to allocate new nodes. |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
724 | */ |
902
5ed7f634f046
implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents:
901
diff
changeset
|
725 | const CxAllocator *allocator; |
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
726 | |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
727 | /** |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
728 | * 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
|
729 | * |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
730 | * Will be \c NULL when \c size is 0. |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
731 | */ |
902
5ed7f634f046
implement cxTreeCreate family of functions
Mike Becker <universe@uap-core.de>
parents:
901
diff
changeset
|
732 | void *root; |
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
733 | |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
734 | /** |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
735 | * A function to create new 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
|
736 | * |
897
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
737 | * Invocations to this function will receive a pointer to this tree |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
738 | * structure as second argument. |
0936916856a2
add allocator and root node pointer to tree structure
Mike Becker <universe@uap-core.de>
parents:
896
diff
changeset
|
739 | * |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
740 | * Nodes MAY use #cx_tree_node_base_s as base layout, but do not need to. |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
741 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
742 | cx_tree_node_create_func node_create; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
743 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
744 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
745 | * An optional simple destructor for the tree nodes. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
746 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
747 | cx_destructor_func simple_destructor; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
748 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
749 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
750 | * An optional advanced destructor for the tree nodes. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
751 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
752 | cx_destructor_func2 advanced_destructor; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
753 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
754 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
755 | * The pointer to additional data that is passed to the advanced destructor. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
756 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
757 | void *destructor_data; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
758 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
759 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
760 | * A function to compare two nodes. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
761 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
762 | cx_tree_search_func search; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
763 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
764 | /** |
905
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
765 | * A function to compare a node with data. |
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
766 | */ |
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
767 | cx_tree_search_data_func search_data; |
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
768 | |
39aa4f106a71
complete implementation of remaining high level tree functions
Mike Becker <universe@uap-core.de>
parents:
904
diff
changeset
|
769 | /** |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
770 | * The number of currently stored elements. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
771 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
772 | size_t size; |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
773 | |
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
774 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
775 | * 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
|
776 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
777 | 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
|
778 | |
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
779 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
780 | * 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
|
781 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
782 | 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
|
783 | |
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
784 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
785 | * 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
|
786 | * 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
|
787 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
788 | 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
|
789 | |
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
790 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
791 | * 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
|
792 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
793 | 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
|
794 | |
898
9b2c12494ccf
prototypes for create and destroy functions
Mike Becker <universe@uap-core.de>
parents:
897
diff
changeset
|
795 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
796 | * 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
|
797 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
798 | ptrdiff_t loc_next; |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
799 | }; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
800 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
801 | /** |
895
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
802 | * 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
|
803 | * node type. |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
804 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
805 | #define CX_TREE_NODE_BASE(type) \ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
806 | 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
|
807 | 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
|
808 | 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
|
809 | 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
|
810 | 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
|
811 | |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
812 | /** |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
813 | * Macro for specifying the layout of a base node tree. |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
814 | */ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
815 | #define cx_tree_node_base_layout \ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
816 | offsetof(struct cx_tree_node_base_s, parent),\ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
817 | offsetof(struct cx_tree_node_base_s, children),\ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
818 | offsetof(struct cx_tree_node_base_s, 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
|
819 | offsetof(struct cx_tree_node_base_s, prev), \ |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
820 | offsetof(struct cx_tree_node_base_s, next) |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
821 | |
ea1ac0e8225c
provide a default tree node layout, but do not make it mandatory
Mike Becker <universe@uap-core.de>
parents:
894
diff
changeset
|
822 | /** |
901
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
823 | * Macro for obtaining the node pointer layout for a specific tree. |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
824 | */ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
825 | #define cx_tree_node_layout(tree) \ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
826 | (tree)->loc_parent,\ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
827 | (tree)->loc_children,\ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
828 | (tree)->loc_last_child,\ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
829 | (tree)->loc_prev, \ |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
830 | (tree)->loc_next |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
831 | |
109567325fe7
add functions to link/unlink nodes manually
Mike Becker <universe@uap-core.de>
parents:
900
diff
changeset
|
832 | /** |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
833 | * The class definition for arbitrary trees. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
834 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
835 | struct cx_tree_class_s { |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
836 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
837 | * Member function for inserting a single element. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
838 | * |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
839 | * Implementations SHALL NOT simply invoke \p insert_many as this comes |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
840 | * with too much overhead. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
841 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
842 | cx_attr_nonnull |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
843 | int (*insert_element)( |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
844 | struct cx_tree_s *tree, |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
845 | const void *data |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
846 | ); |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
847 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
848 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
849 | * Member function for inserting multiple elements. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
850 | * |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
851 | * Implementations SHALL avoid to perform a full search in the tree for |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
852 | * every element even though the source data MAY be unsorted. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
853 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
854 | cx_attr_nonnull |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
855 | size_t (*insert_many)( |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
856 | struct cx_tree_s *tree, |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
857 | struct cx_iterator_base_s *iter, |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
858 | size_t n |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
859 | ); |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
860 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
861 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
862 | * Member function for finding a node. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
863 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
864 | cx_attr_nonnull |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
865 | void *(*find)( |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
866 | struct cx_tree_s *tree, |
896
7e09c76390c3
allow find() member function to start in an arbitrary subtree
Mike Becker <universe@uap-core.de>
parents:
895
diff
changeset
|
867 | const void *subtree, |
930
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
868 | const void *data, |
6540096c17b7
add max depth for tree search - closes #459
Mike Becker <universe@uap-core.de>
parents:
927
diff
changeset
|
869 | size_t depth |
894
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
870 | ); |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
871 | }; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
872 | |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
873 | /** |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
874 | * Common type for all tree implementations. |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
875 | */ |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
876 | typedef struct cx_tree_s CxTree; |
89cd8dfdc3c2
first draft of a class for high level trees
Mike Becker <universe@uap-core.de>
parents:
893
diff
changeset
|
877 | |
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
878 | |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
879 | /** |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
880 | * Destroys a node and it's subtree. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
881 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
882 | * 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
|
883 | * 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
|
884 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
885 | * When this function is invoked on the root node of the tree, it destroys the |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
886 | * tree contents, but - in contrast to #cxTreeDestroy() - not the tree |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
887 | * structure, leaving an empty tree behind. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
888 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
889 | * \note The destructor function, if any, will \em not be invoked. That means |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
890 | * 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
|
891 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
892 | * \attention This function will not free the memory of the nodes with the |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
893 | * 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
|
894 | * 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
|
895 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
896 | * @param tree the tree |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
897 | * @param node the node to remove |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
898 | * @see cxTreeDestroy() |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
899 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
900 | cx_attr_nonnull |
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
901 | void cxTreeDestroySubtree(CxTree *tree, void *node); |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
902 | |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
903 | |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
904 | /** |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
905 | * Destroys the tree contents. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
906 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
907 | * 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
|
908 | * 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
|
909 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
910 | * 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
|
911 | * root node of the tree. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
912 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
913 | * \attention Be careful when calling this function when no destructor function |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
914 | * is registered that actually frees the memory of nodes. In that case you will |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
915 | * need a reference to the (former) root node of the tree somewhere or |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
916 | * otherwise you will be leaking memory. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
917 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
918 | * @param tree the tree |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
919 | * @see cxTreeDestroySubtree() |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
920 | */ |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
921 | #define cxTreeClear(tree) cxTreeDestroySubtree(tree, tree->root) |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
922 | |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
923 | /** |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
924 | * Destroys the tree structure. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
925 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
926 | * 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
|
927 | * nodes. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
928 | * 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
|
929 | * the advanced destructor. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
930 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
931 | * \attention This function will only invoke the destructor functions |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
932 | * on the nodes. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
933 | * 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
|
934 | * 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
|
935 | * destructor is already freeing the memory. |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
936 | * |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
937 | * @param tree the tree to destroy |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
938 | */ |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
939 | static inline void cxTreeDestroy(CxTree *tree) { |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
940 | if (tree == NULL) return; |
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
941 | if (tree->root != NULL) { |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
942 | cxTreeClear(tree); |
913
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
943 | } |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
944 | cxFree(tree->allocator, tree); |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
945 | } |
72db8e42b95e
implement cxTreeDestroyNode and cxTreeDestroySubtree - resolves #438
Mike Becker <universe@uap-core.de>
parents:
909
diff
changeset
|
946 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
947 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
948 | * Creates a new tree structure based on the specified layout. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
949 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
950 | * The specified \p allocator will be used for creating the tree struct |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
951 | * and SHALL be used by \p create_func to allocate memory for the nodes. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
952 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
953 | * \note This function will also register an advanced destructor which |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
954 | * will free the nodes with the allocator's free() method. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
955 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
956 | * @param allocator the allocator that shall be used |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
988
diff
changeset
|
957 | * (if \c NULL, a default stdlib allocator will be used) |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
958 | * @param create_func a function that creates new nodes |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
959 | * @param search_func a function that compares two nodes |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
960 | * @param search_data_func a function that compares a node with data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
961 | * @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
|
962 | * @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
|
963 | * @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
|
964 | * 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
|
965 | * @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
|
966 | * @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
|
967 | * @return the new tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
968 | * @see cxTreeCreateSimple() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
969 | * @see cxTreeCreateWrapped() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
970 | */ |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
988
diff
changeset
|
971 | cx_attr_nonnull_arg(2, 3, 4) |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
972 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
973 | cx_attr_malloc |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
974 | cx_attr_dealloc(cxTreeDestroy, 1) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
975 | CxTree *cxTreeCreate( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
976 | const CxAllocator *allocator, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
977 | cx_tree_node_create_func create_func, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
978 | cx_tree_search_func search_func, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
979 | cx_tree_search_data_func search_data_func, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
980 | ptrdiff_t loc_parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
981 | ptrdiff_t loc_children, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
982 | ptrdiff_t loc_last_child, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
983 | ptrdiff_t loc_prev, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
984 | ptrdiff_t loc_next |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
985 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
986 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
987 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
988 | * Creates a new tree structure based on a default layout. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
989 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
990 | * Nodes created by \p create_func MUST contain #cx_tree_node_base_s as first |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
991 | * member (or at least respect the default offsets specified in the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
992 | * struct) and they MUST be allocated with the specified allocator. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
993 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
994 | * \note This function will also register an advanced destructor which |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
995 | * will free the nodes with the allocator's free() method. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
996 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
997 | * @param allocator the allocator that shall be used |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
998 | * @param create_func a function that creates new nodes |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
999 | * @param search_func a function that compares two nodes |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1000 | * @param search_data_func a function that compares a node with data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1001 | * @return the new tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1002 | * @see cxTreeCreate() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1003 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1004 | #define cxTreeCreateSimple(\ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1005 | allocator, create_func, search_func, search_data_func \ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1006 | ) cxTreeCreate(allocator, create_func, search_func, search_data_func, \ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1007 | cx_tree_node_base_layout) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1008 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1009 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1010 | * Creates a new tree structure based on an existing tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1011 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1012 | * The specified \p allocator will be used for creating the tree struct. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1013 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1014 | * \attention This function will create an incompletely defined tree structure |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1015 | * where neither the create function, the search function, nor a destructor |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1016 | * will be set. If you wish to use any of this functionality for the wrapped |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1017 | * tree, you need to specify those functions afterwards. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1018 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1019 | * @param allocator the allocator that was used for nodes of the wrapped tree |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
988
diff
changeset
|
1020 | * (if \c NULL, a default stdlib allocator is assumed) |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1021 | * @param root the root node of the tree that shall be wrapped |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1022 | * @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
|
1023 | * @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
|
1024 | * @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
|
1025 | * 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
|
1026 | * @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
|
1027 | * @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
|
1028 | * @return the new tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1029 | * @see cxTreeCreate() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1030 | */ |
989
8aa57a7fecc4
improve consistency for allocator arguments - fixes #485
Mike Becker <universe@uap-core.de>
parents:
988
diff
changeset
|
1031 | cx_attr_nonnull_arg(2) |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1032 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1033 | cx_attr_malloc |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1034 | cx_attr_dealloc(cxTreeDestroy, 1) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1035 | CxTree *cxTreeCreateWrapped( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1036 | const CxAllocator *allocator, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1037 | void *root, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1038 | ptrdiff_t loc_parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1039 | ptrdiff_t loc_children, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1040 | ptrdiff_t loc_last_child, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1041 | ptrdiff_t loc_prev, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1042 | ptrdiff_t loc_next |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1043 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1044 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1045 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1046 | * Inserts data into the tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1047 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1048 | * \remark For this function to work, the tree needs specified search and |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1049 | * create functions, which might not be available for wrapped trees |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1050 | * (see #cxTreeCreateWrapped()). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1051 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1052 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1053 | * @param data the data to insert |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1054 | * @return zero on success, non-zero on failure |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1055 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1056 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1057 | static inline int cxTreeInsert( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1058 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1059 | const void *data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1060 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1061 | return tree->cl->insert_element(tree, data); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1062 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1063 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1064 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1065 | * Inserts elements provided by an iterator efficiently into the tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1066 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1067 | * \remark For this function to work, the tree needs specified search and |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1068 | * create functions, which might not be available for wrapped trees |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1069 | * (see #cxTreeCreateWrapped()). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1070 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1071 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1072 | * @param iter the iterator providing the elements |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1073 | * @param n the maximum number of elements to insert |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1074 | * @return the number of elements that could be successfully inserted |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1075 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1076 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1077 | static inline size_t cxTreeInsertIter( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1078 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1079 | struct cx_iterator_base_s *iter, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1080 | size_t n |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1081 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1082 | return tree->cl->insert_many(tree, iter, n); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1083 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1084 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1085 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1086 | * Inserts an array of data efficiently into the tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1087 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1088 | * \remark For this function to work, the tree needs specified search and |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1089 | * create functions, which might not be available for wrapped trees |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1090 | * (see #cxTreeCreateWrapped()). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1091 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1092 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1093 | * @param data the array of data to insert |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1094 | * @param elem_size the size of each element in the array |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1095 | * @param n the number of elements in the array |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1096 | * @return the number of elements that could be successfully inserted |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1097 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1098 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1099 | static inline size_t cxTreeInsertArray( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1100 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1101 | const void *data, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1102 | size_t elem_size, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1103 | size_t n |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1104 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1105 | if (n == 0) return 0; |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1106 | if (n == 1) return 0 == cxTreeInsert(tree, data) ? 1 : 0; |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1107 | CxIterator iter = cxIterator(data, elem_size, n); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1108 | return cxTreeInsertIter(tree, cxIteratorRef(iter), n); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1109 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1110 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1111 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1112 | * Searches the data in the specified tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1113 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1114 | * \remark For this function to work, the tree needs a specified \c search_data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1115 | * function, which might not be available wrapped trees |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1116 | * (see #cxTreeCreateWrapped()). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1117 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1118 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1119 | * @param data the data to search for |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1120 | * @return the first matching node, or \c NULL when the data cannot be found |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1121 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1122 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1123 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1124 | static inline void *cxTreeFind( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1125 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1126 | const void *data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1127 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1128 | return tree->cl->find(tree, tree->root, data, 0); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1129 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1130 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1131 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1132 | * Searches the data in the specified subtree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1133 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1134 | * When \p max_depth is zero, the depth is not limited. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1135 | * The \p subtree_root itself is on depth 1 and its children have depth 2. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1136 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1137 | * \note When \p subtree_root is not part of the \p tree, the behavior is |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1138 | * undefined. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1139 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1140 | * \remark For this function to work, the tree needs a specified \c search_data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1141 | * function, which might not be the case for wrapped trees |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1142 | * (see #cxTreeCreateWrapped()). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1143 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1144 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1145 | * @param data the data to search for |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1146 | * @param subtree_root the node where to start |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1147 | * @param max_depth the maximum search depth |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1148 | * @return the first matching node, or \c NULL when the data cannot be found |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1149 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1150 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1151 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1152 | static inline void *cxTreeFindInSubtree( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1153 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1154 | const void *data, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1155 | void *subtree_root, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1156 | size_t max_depth |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1157 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1158 | return tree->cl->find(tree, subtree_root, data, max_depth); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1159 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1160 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1161 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1162 | * Determines the size of the specified subtree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1163 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1164 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1165 | * @param subtree_root the root node of the subtree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1166 | * @return the number of nodes in the specified subtree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1167 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1168 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1169 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1170 | size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1171 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1172 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1173 | * Determines the depth of the specified subtree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1174 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1175 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1176 | * @param subtree_root the root node of the subtree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1177 | * @return the tree depth including the \p subtree_root |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1178 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1179 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1180 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1181 | size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1182 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1183 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1184 | * Determines the depth of the entire tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1185 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1186 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1187 | * @return the tree depth, counting the root as one |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1188 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1189 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1190 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1191 | size_t cxTreeDepth(CxTree *tree); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1192 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1193 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1194 | * Creates a depth-first iterator for the specified tree starting in \p node. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1195 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1196 | * 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
|
1197 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1198 | * @param tree the tree to iterate |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1199 | * @param node the node where to start |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1200 | * @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
|
1201 | * leaving the subtree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1202 | * @return a tree iterator (depth-first) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1203 | * @see cxTreeVisit() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1204 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1205 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1206 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1207 | static inline CxTreeIterator cxTreeIterateSubtree( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1208 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1209 | void *node, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1210 | bool visit_on_exit |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1211 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1212 | return cx_tree_iterator( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1213 | node, visit_on_exit, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1214 | tree->loc_children, tree->loc_next |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1215 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1216 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1217 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1218 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1219 | * Creates a breadth-first iterator for the specified tree starting in \p node. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1220 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1221 | * 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
|
1222 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1223 | * @param tree the tree to iterate |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1224 | * @param node the node where to start |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1225 | * @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
|
1226 | * @see cxTreeIterate() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1227 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1228 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1229 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1230 | static inline CxTreeVisitor cxTreeVisitSubtree(CxTree *tree, void *node) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1231 | return cx_tree_visitor( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1232 | node, tree->loc_children, tree->loc_next |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1233 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1234 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1235 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1236 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1237 | * Creates a depth-first iterator for the specified tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1238 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1239 | * @param tree the tree to iterate |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1240 | * @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
|
1241 | * leaving the subtree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1242 | * @return a tree iterator (depth-first) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1243 | * @see cxTreeVisit() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1244 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1245 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1246 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1247 | static inline CxTreeIterator cxTreeIterate( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1248 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1249 | bool visit_on_exit |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1250 | ) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1251 | return cxTreeIterateSubtree(tree, tree->root, visit_on_exit); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1252 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1253 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1254 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1255 | * Creates a breadth-first iterator for the specified tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1256 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1257 | * @param tree the tree to iterate |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1258 | * @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
|
1259 | * @see cxTreeIterate() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1260 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1261 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1262 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1263 | static inline CxTreeVisitor cxTreeVisit(CxTree *tree) { |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1264 | return cxTreeVisitSubtree(tree, tree->root); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1265 | } |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1266 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1267 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1268 | * Sets the (new) parent of the specified child. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1269 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1270 | * If the \p child is not already member of the tree, this function behaves |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1271 | * as #cxTreeAddChildNode(). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1272 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1273 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1274 | * @param parent the (new) parent of the child |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1275 | * @param child the node to add |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1276 | * @see cxTreeAddChildNode() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1277 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1278 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1279 | void cxTreeSetParent( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1280 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1281 | void *parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1282 | void *child |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1283 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1284 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1285 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1286 | * Adds a new node to the tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1287 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1288 | * If the \p child is already member of the tree, the behavior is undefined. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1289 | * 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
|
1290 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1291 | * \attention The node may be externally created, but MUST obey the same rules |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1292 | * as if it was created by the tree itself with #cxTreeAddChild() (e.g. use |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1293 | * the same allocator). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1294 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1295 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1296 | * @param parent the parent of the node to add |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1297 | * @param child the node to add |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1298 | * @see cxTreeSetParent() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1299 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1300 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1301 | void cxTreeAddChildNode( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1302 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1303 | void *parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1304 | void *child |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1305 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1306 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1307 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1308 | * 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
|
1309 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1310 | * With this function you can decide where exactly the new node shall be added. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1311 | * If you specified an appropriate search function, you may want to consider |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1312 | * leaving this task to the tree by using #cxTreeInsert(). |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1313 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1314 | * Be aware that adding nodes at arbitrary locations in the tree might cause |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1315 | * wrong or undesired results when subsequently invoking #cxTreeInsert() and |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1316 | * the invariant imposed by the search function does not hold any longer. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1317 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1318 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1319 | * @param parent the parent node of the new node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1320 | * @param data the data that will be submitted to the create function |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1321 | * @return zero when the new node was created, non-zero on allocation failure |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1322 | * @see cxTreeInsert() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1323 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1324 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1325 | int cxTreeAddChild( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1326 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1327 | void *parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1328 | const void *data |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1329 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1330 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1331 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1332 | * 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
|
1333 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1334 | * 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
|
1335 | * This callback is invoked by #cxTreeRemoveNode() and #cxTreeDestroyNode() |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1336 | * 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
|
1337 | * removed node. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1338 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1339 | * @param node the affected node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1340 | * @param old_parent the old parent of the node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1341 | * @param new_parent the new parent of the node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1342 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1343 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1344 | typedef void (*cx_tree_relink_func)( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1345 | void *node, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1346 | const void *old_parent, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1347 | const void *new_parent |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1348 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1349 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1350 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1351 | * 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
|
1352 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1353 | * 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
|
1354 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1355 | * \note The destructor function, if any, will \em not be invoked. That means |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1356 | * 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
|
1357 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1358 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1359 | * @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
|
1360 | * @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
|
1361 | * node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1362 | * @return zero on success, non-zero if \p node is the root node of the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1363 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1364 | cx_attr_nonnull_arg(1, 2) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1365 | int cxTreeRemoveNode( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1366 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1367 | void *node, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1368 | cx_tree_relink_func relink_func |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1369 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1370 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1371 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1372 | * Removes a node and it's subtree from the tree. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1373 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1374 | * 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
|
1375 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1376 | * \note The destructor function, if any, will \em not be invoked. That means |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1377 | * 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
|
1378 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1379 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1380 | * @param node the node to remove |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1381 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1382 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1383 | void cxTreeRemoveSubtree(CxTree *tree, void *node); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1384 | |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1385 | /** |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1386 | * 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
|
1387 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1388 | * 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
|
1389 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1390 | * 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
|
1391 | * the advanced destructor. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1392 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1393 | * \attention This function will not free the memory of the node with the |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1394 | * 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
|
1395 | * and would therefore result in a double-free. |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1396 | * |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1397 | * @param tree the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1398 | * @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
|
1399 | * @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
|
1400 | * node |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1401 | * @return zero on success, non-zero if \p node is the root node of the tree |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1402 | */ |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1403 | cx_attr_nonnull_arg(1, 2) |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1404 | int cxTreeDestroyNode( |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1405 | CxTree *tree, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1406 | void *node, |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1407 | cx_tree_relink_func relink_func |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1408 | ); |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
930
diff
changeset
|
1409 | |
816
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1410 | #ifdef __cplusplus |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1411 | } // extern "C" |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1412 | #endif |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1413 | |
425234b05dff
add first basic low level tree functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1414 | #endif //UCX_TREE_H |