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