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