ucx/cx/tree.h

Thu, 01 Jan 2026 17:59:32 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 01 Jan 2026 17:59:32 +0100
changeset 38
27fadadaae31
parent 30
d33eaaec15da
permissions
-rw-r--r--

update ucx

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

mercurial