ucx/cx/tree.h

Sat, 08 Nov 2025 23:06:11 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 08 Nov 2025 23:06:11 +0100
changeset 888
af685cc9d623
parent 854
1c8401ece69e
permissions
-rw-r--r--

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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
29 * @file tree.h
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
30 * @brief Interface for tree implementations.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
31 * @author Mike Becker
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
32 * @author Olaf Wintermann
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
50 * This iterator is not position-aware in a strict sense, as it does not assume
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
51 * a particular order of elements in the tree. However, the iterator keeps track
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
55 * @note Objects that are pointed to by an iterator are mutable through that
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
56 * iterator. However, if the
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
57 * underlying data structure is mutated by other means than this iterator (e.g.,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
58 * elements added or removed), the iterator becomes invalid (regardless of what
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
74 * when all its children have been processed.
816
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 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
100 * Stores a copy of the pointer to the successor of the visited node.
816
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.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
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.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
151 * This iterator needs to maintain a visitor queue that will be automatically
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
152 * freed once the iterator becomes invalid.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
153 * If you want to discard the iterator before, you MUST manually call
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
156 * This iterator is not position-aware in a strict sense, as it does not assume
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
157 * a particular order of elements in the tree. However, the iterator keeps track
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
161 * @note Objects that are pointed to by an iterator are mutable through that
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
162 * iterator. However, if the
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
163 * underlying data structure is mutated by other means than this iterator (e.g.,
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
164 * elements added or removed), the iterator becomes invalid (regardless of what
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
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
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
214 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
215 CX_EXPORT void cxTreeIteratorDispose(CxTreeIterator *iter);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 /**
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
218 * 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
219 * @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
220 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
221 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
222 CX_EXPORT void cxTreeVisitorDispose(CxTreeVisitor *visitor);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
223
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
224 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
225 * 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
226 * 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
227 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
228 * @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
229 */
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
230 #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
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 * 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
234 * 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
235 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
236 * @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
237 */
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
238 #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
239
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
240 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
241 * 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
242 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
243 * If the node already has a parent, it is unlinked, first.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
244 * 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
245 * 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
246 *
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
247 * @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
248 * @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
249 * @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
250 * @param loc_children offset in the node struct for the children linked list
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
251 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
252 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
253 * @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
254 * @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
255 * @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
256 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
257 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
258 CX_EXPORT void cx_tree_link(void *parent, void *node,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
259 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
260 ptrdiff_t loc_prev, ptrdiff_t loc_next);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
261
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
262 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
263 * 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
264 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
265 * 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
266 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
267 * @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
268 * @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
269 * @param loc_children offset in the node struct for the children linked list
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
270 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
271 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
272 * @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
273 * @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
274 * @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
275 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
276 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
277 CX_EXPORT void cx_tree_unlink(void *node,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
278 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
279 ptrdiff_t loc_prev, ptrdiff_t loc_next);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
280
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
281 /**
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
282 * Macro that can be used instead of the magic value for infinite search depth.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
283 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
284 #define CX_TREE_SEARCH_INFINITE_DEPTH 0
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
285
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
286 /**
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
287 * 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
288 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
289 * A function of this kind shall check if the specified @p node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
290 * 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
291 * the data.
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
292 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
293 * 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
294 * match is, where a negative number means that it does not match at all.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
295 * Zero means exact match and a positive number is an implementation defined
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
296 * 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
297 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
298 * For example, consider a tree that stores file path information.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
299 * A node which is describing a parent directory of a searched file shall
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
300 * 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
301 * 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
302 * prefix of the searched filename, the function would return -1 to indicate
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
303 * 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
304 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
305 * @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
306 * @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
307 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
308 * @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
309 * positive if one of the children might contain the data,
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
310 * negative if neither the node nor the children contains the data
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
311 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
312 typedef int (*cx_tree_search_data_func)(const void *node, const void *data);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
313
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
314
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
315 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
316 * Function pointer for a search function.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
317 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
318 * A function of this kind shall check if the specified @p node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
319 * contains the same @p data as @p new_node or if one of the children might
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
320 * contain the data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
321 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
322 * The function should use the returned integer to indicate how close the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
323 * match is, where a negative number means that it does not match at all.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
324 * Zero means exact match and a positive number is an implementation defined
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
325 * measure for the distance to an exact match.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
326 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
327 * For example, consider a tree that stores file path information.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
328 * A node which is describing a parent directory of a searched file shall
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
329 * return a positive number to indicate that a child node might contain the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
330 * searched item. On the other hand, if the node denotes a path that is not a
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
331 * prefix of the searched filename, the function would return -1 to indicate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
332 * that the search does not need to be continued in that branch.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
333 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
334 * @param node the node that is currently investigated
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
335 * @param new_node a new node with the information which is searched
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
336 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
337 * @return 0 if @p node contains the same data as @p new_node,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
338 * positive if one of the children might contain the data,
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
339 * negative if neither the node nor the children contains the data
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
340 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
341 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
342
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
343 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
344 * 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
345 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
346 * When the data cannot be found exactly, the search function might return the
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
347 * closest result, which might be a good starting point for adding a new node
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
348 * 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
349 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
350 * Depending on the tree structure, it is not necessarily guaranteed that the
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
351 * "closest" match is uniquely defined. This function will search for a node
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
352 * with the best match according to the @p sfunc (meaning: the return value of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
353 * @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
354 * 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
355 *
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
356 * @param root the root node
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
357 * @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
358 * @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
359 * @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
360 * @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
361 * @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
362 * @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
363 * @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
364 * 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
365 * 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
366 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
367 cx_attr_nonnull cx_attr_access_w(5)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
368 CX_EXPORT int cx_tree_search_data(const void *root, size_t depth,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
369 const void *data, cx_tree_search_data_func sfunc,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
370 void **result, ptrdiff_t loc_children, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
371
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
372 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
373 * Searches for a node in a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
374 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
375 * When no node with the same data can be found, the search function might
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
376 * return the closest result, which might be a good starting point for adding the
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
377 * new node to the tree (see also #cx_tree_add()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
378 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
379 * Depending on the tree structure, it is not necessarily guaranteed that the
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
380 * "closest" match is uniquely defined. This function will search for a node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
381 * with the best match according to the @p sfunc (meaning: the return value of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
382 * @p sfunc which is closest to zero). If that is also ambiguous, an arbitrary
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
383 * node matching the criteria is returned.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
384 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
385 * @param root the root node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
386 * @param depth the maximum depth (zero=indefinite, one=just root)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
387 * @param node the node to search for
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
388 * @param sfunc the search function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
389 * @param result where the result shall be stored
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
390 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
391 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
392 * @return zero if the node was found exactly, positive if a node was found that
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
393 * could contain the node (but doesn't right now), negative if the tree does not
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
394 * contain any node that might be related to the searched data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
395 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
396 cx_attr_nonnull cx_attr_access_w(5)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
397 CX_EXPORT int cx_tree_search(const void *root, size_t depth,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
398 const void *node, cx_tree_search_func sfunc,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
399 void **result, ptrdiff_t loc_children, ptrdiff_t loc_next);
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
400
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
401 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
402 * 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
403 *
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
404 * @note A tree iterator needs to maintain a stack of visited nodes, which is
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
405 * allocated using the cxDefaultAllocator.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
406 * When the iterator becomes invalid, this memory is automatically released.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
407 * However, if you wish to cancel the iteration before the iterator becomes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
408 * 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
409 * the memory.
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
410 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
411 * @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
412 *
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
413 * @param root the root node
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
414 * @param visit_on_exit set to true, when the iterator shall visit a node again
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
415 * 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
416 * @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
417 * @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
418 * @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
419 * @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
420 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
421 cx_attr_nodiscard
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
422 CX_EXPORT CxTreeIterator cx_tree_iterator(void *root, bool visit_on_exit,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
423 ptrdiff_t loc_children, ptrdiff_t loc_next);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
424
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
425 /**
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
426 * 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
427 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
428 * @note A tree visitor needs to maintain a queue of to-be visited nodes, which
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
429 * is allocated using the cxDefaultAllocator.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
430 * When the visitor becomes invalid, this memory is automatically released.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
431 * However, if you wish to cancel the iteration before the visitor becomes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
432 * 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
433 * the memory.
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
434 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
435 * @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
436 *
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
437 * @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
438 * @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
439 * @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
440 * @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
441 * @see cxTreeVisitorDispose()
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
442 */
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
443 cx_attr_nodiscard
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
444 CX_EXPORT CxTreeVisitor cx_tree_visitor(void *root,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
445 ptrdiff_t loc_children, ptrdiff_t loc_next);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
447 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
448 * Describes a function that creates a tree node from the specified data.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
449 * The first argument points to the data the node shall contain, and
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
450 * the second argument may be used for additional data (e.g., an allocator).
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
451 * Functions of this type shall either return a new pointer to a newly
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
452 * created node or @c NULL when allocation fails.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
453 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
454 * @note the function may leave the node pointers in the struct uninitialized.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
455 * The caller is responsible to set them according to the intended use case.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
456 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
457 typedef void *(*cx_tree_node_create_func)(const void *, void *);
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
458
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
459 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
460 * The local search depth for a new subtree when adding multiple elements.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
461 * The default value is 3.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
462 * This variable is used by #cx_tree_add_array() and #cx_tree_add_iter() to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
463 * implement optimized insertion of multiple elements into a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
464 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
465 CX_EXPORT extern unsigned int cx_tree_add_look_around_depth;
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
466
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
467 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
468 * Adds multiple elements efficiently to a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
469 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
470 * Once an element cannot be added to the tree, this function returns, leaving
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
471 * the iterator in a valid state pointing to the element that could not be
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
472 * added.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
473 * Also, the pointer of the created node will be stored to @p failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
474 * The integer returned by this function denotes the number of elements obtained
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
475 * from the @p iter that have been successfully processed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
476 * When all elements could be processed, a @c NULL pointer will be written to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
477 * @p failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
478 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
479 * The advantage of this function compared to multiple invocations of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
480 * #cx_tree_add() is that the search for the insert locations is not always
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
481 * started from the root node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
482 * Instead, the function checks #cx_tree_add_look_around_depth many parent nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
483 * of the current insert location before starting from the root node again.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
484 * When the variable is set to zero, only the last found location is checked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
485 * again.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
486 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
487 * Refer to the documentation of #cx_tree_add() for more details.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
488 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
489 * @param iter a pointer to an arbitrary iterator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
490 * @param num the maximum number of elements to obtain from the iterator
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
491 * @param sfunc a search function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
492 * @param cfunc a node creation function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
493 * @param cdata optional additional data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
494 * @param root the root node of the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
495 * @param failed location where the pointer to a failed node shall be stored
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
496 * @param loc_parent offset in the node struct for the parent pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
497 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
498 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
499 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
500 * @param loc_prev optional offset in the node struct for the prev pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
501 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
502 * @return the number of nodes created and added
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
503 * @see cx_tree_add()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
504 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
505 cx_attr_nonnull_arg(1, 3, 4, 6, 7) cx_attr_access_w(6)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
506 CX_EXPORT size_t cx_tree_add_iter(struct cx_iterator_base_s *iter, size_t num,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
507 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
508 void *cdata, void **failed, void *root,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
509 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
510 ptrdiff_t loc_prev, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
511
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
512 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
513 * Adds multiple elements efficiently to a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
514 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
515 * Once an element cannot be added to the tree, this function returns, storing
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
516 * the pointer of the created node to @p failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
517 * The integer returned by this function denotes the number of elements from
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
518 * the @p src array that have been successfully processed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
519 * When all elements could be processed, a @c NULL pointer will be written to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
520 * @p failed.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
521 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
522 * The advantage of this function compared to multiple invocations of
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
523 * #cx_tree_add() is that the search for the insert locations is not always
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
524 * started from the root node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
525 * Instead, the function checks #cx_tree_add_look_around_depth many parent nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
526 * of the current insert location before starting from the root node again.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
527 * When the variable is set to zero, only the last found location is checked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
528 * again.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
529 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
530 * Refer to the documentation of #cx_tree_add() for more details.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
531 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
532 * @param src a pointer to the source data array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
533 * @param num the number of elements in the @p src array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
534 * @param elem_size the size of each element in the @p src array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
535 * @param sfunc a search function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
536 * @param cfunc a node creation function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
537 * @param cdata optional additional data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
538 * @param failed location where the pointer to a failed node shall be stored
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
539 * @param root the root node of the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
540 * @param loc_parent offset in the node struct for the parent pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
541 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
542 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
543 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
544 * @param loc_prev optional offset in the node struct for the prev pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
545 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
546 * @return the number of array elements successfully processed
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
547 * @see cx_tree_add()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
548 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
549 cx_attr_nonnull_arg(1, 4, 5, 7, 8) cx_attr_access_w(7)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
550 CX_EXPORT size_t cx_tree_add_array(const void *src, size_t num, size_t elem_size,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
551 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
552 void *cdata, void **failed, void *root,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
553 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
554 ptrdiff_t loc_prev, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
555
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
556 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
557 * Adds data to a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
558 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
559 * An adequate location where to add the new tree node is searched with the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
560 * specified @p sfunc.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
561 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
562 * When a location is found, the @p cfunc will be invoked with @p cdata.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
563 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
564 * The node returned by @p cfunc will be linked into the tree.
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
565 * When @p sfunc returns a positive integer, the new node will be linked as a
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
566 * child. The other children (now siblings of the new node) are then checked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
567 * with @p sfunc, whether they could be children of the new node and re-linked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
568 * accordingly.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
569 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
570 * When @p sfunc returns zero and the found node has a parent, the new
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
571 * node will be added as a sibling - otherwise, the new node will be added
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
572 * as a child.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
573 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
574 * When @p sfunc returns a negative value, the new node will not be added to
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
575 * the tree, and this function returns a non-zero value.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
576 * The caller should check if @p cnode contains a node pointer and deal with the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
577 * node that could not be added.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
578 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
579 * This function also returns a non-zero value when @p cfunc tries to allocate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
580 * a new node but fails to do so. In that case, the pointer stored to @p cnode
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
581 * will be @c NULL.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
582 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
583 * Multiple elements can be added more efficiently with
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
584 * #cx_tree_add_array() or #cx_tree_add_iter().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
585 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
586 * @param src a pointer to the data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
587 * @param sfunc a search function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
588 * @param cfunc a node creation function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
589 * @param cdata optional additional data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
590 * @param cnode the location where a pointer to the new node is stored
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
591 * @param root the root node of the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
592 * @param loc_parent offset in the node struct for the parent pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
593 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
594 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
595 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
596 * @param loc_prev optional offset in the node struct for the prev pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
597 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
598 * @return zero when a new node was created and added to the tree,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
599 * non-zero otherwise
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
600 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
601 cx_attr_nonnull_arg(1, 2, 3, 5, 6) cx_attr_access_w(5)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
602 CX_EXPORT int cx_tree_add(const void *src,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
603 cx_tree_search_func sfunc, cx_tree_node_create_func cfunc,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
604 void *cdata, void **cnode, void *root,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
605 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
606 ptrdiff_t loc_prev, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
607
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
608
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
609 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
610 * Tree class type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
611 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
612 typedef struct cx_tree_class_s cx_tree_class;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
613
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
614 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
615 * Base structure that can be used for tree nodes in a #CxTree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
616 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
617 struct cx_tree_node_base_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
618 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
619 * Pointer to the parent.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
620 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
621 struct cx_tree_node_base_s *parent;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
622 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
623 * Pointer to the first child.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
624 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
625 struct cx_tree_node_base_s *children;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
626 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
627 * Pointer to the last child.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
628 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
629 struct cx_tree_node_base_s *last_child;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
630 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
631 * Pointer to the previous sibling.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
632 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
633 struct cx_tree_node_base_s *prev;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
634 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
635 * Pointer to the next sibling.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
636 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
637 struct cx_tree_node_base_s *next;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
638 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
639
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
640 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
641 * Structure for holding the base data of a tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
642 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
643 struct cx_tree_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
644 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
645 * The tree class definition.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
646 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
647 const cx_tree_class *cl;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
648
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
649 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
650 * Allocator to allocate new nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
651 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
652 const CxAllocator *allocator;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
653
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
654 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
655 * A pointer to the root node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
656 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
657 * Will be @c NULL when @c size is 0.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
658 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
659 void *root;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
660
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
661 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
662 * A function to create new nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
663 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
664 * Invocations to this function will receive a pointer to this tree
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
665 * structure as the second argument.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
666 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
667 * Nodes MAY use #cx_tree_node_base_s as the base layout, but do not need to.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
668 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
669 cx_tree_node_create_func node_create;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
670
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
671 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
672 * An optional simple destructor for the tree nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
673 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
674 cx_destructor_func simple_destructor;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
675
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
676 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
677 * An optional advanced destructor for the tree nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
678 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
679 cx_destructor_func2 advanced_destructor;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
680
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
681 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
682 * The pointer to additional data that is passed to the advanced destructor.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
683 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
684 void *destructor_data;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
685
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
686 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
687 * A function to compare two nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
688 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
689 cx_tree_search_func search;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
690
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
691 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
692 * A function to compare a node with data.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
693 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
694 cx_tree_search_data_func search_data;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
695
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
696 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
697 * The number of currently stored elements.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
698 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
699 size_t size;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
700
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
701 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
702 * Offset in the node struct for the parent pointer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
703 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
704 ptrdiff_t loc_parent;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
705
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
706 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
707 * Offset in the node struct for the children linked list.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
708 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
709 ptrdiff_t loc_children;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
710
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
711 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
712 * Optional offset in the node struct for the pointer to the last child
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
713 * in the linked list (negative if there is no such pointer).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
714 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
715 ptrdiff_t loc_last_child;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
716
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
717 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
718 * Offset in the node struct for the previous sibling pointer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
719 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
720 ptrdiff_t loc_prev;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
721
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
722 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
723 * Offset in the node struct for the next sibling pointer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
724 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
725 ptrdiff_t loc_next;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
726 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
727
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
728 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
729 * Macro to roll out the #cx_tree_node_base_s structure with a custom
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
730 * node type.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
731 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
732 * Must be used as the first member in your custom tree struct.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
733 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
734 * @param type the data type for the nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
735 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
736 #define CX_TREE_NODE_BASE(type) \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
737 type *parent; \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
738 type *children;\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
739 type *last_child;\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
740 type *prev;\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
741 type *next
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
742
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
743 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
744 * Macro for specifying the layout of a base node tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
745 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
746 * When your tree uses #CX_TREE_NODE_BASE, you can use this
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
747 * macro in all tree functions that expect the layout parameters
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
748 * @c loc_parent, @c loc_children, @c loc_last_child, @c loc_prev,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
749 * and @c loc_next.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
750 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
751 #define cx_tree_node_base_layout \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
752 offsetof(struct cx_tree_node_base_s, parent),\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
753 offsetof(struct cx_tree_node_base_s, children),\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
754 offsetof(struct cx_tree_node_base_s, last_child),\
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
755 offsetof(struct cx_tree_node_base_s, prev), \
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
756 offsetof(struct cx_tree_node_base_s, next)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
757
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
758 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
759 * The class definition for arbitrary trees.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
760 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
761 struct cx_tree_class_s {
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
762 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
763 * Member function for inserting a single element.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
764 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
765 * Implementations SHALL NOT simply invoke @p insert_many as this comes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
766 * with too much overhead.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
767 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
768 int (*insert_element)(struct cx_tree_s *tree, const void *data);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
769
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
770 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
771 * Member function for inserting multiple elements.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
772 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
773 * Implementations SHALL avoid performing a full search in the tree for
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
774 * every element even though the source data MAY be unsorted.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
775 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
776 size_t (*insert_many)(struct cx_tree_s *tree, struct cx_iterator_base_s *iter, size_t n);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
777
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
778 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
779 * Member function for finding a node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
780 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
781 void *(*find)(struct cx_tree_s *tree, const void *subtree, const void *data, size_t depth);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
782 };
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
783
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
784 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
785 * Common type for all tree implementations.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
786 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
787 typedef struct cx_tree_s CxTree;
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
788
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
789
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
790 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
791 * Destroys a node and its subtree.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
792 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
793 * It is guaranteed that the simple destructor is invoked before
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
794 * the advanced destructor, starting with the leaf nodes of the subtree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
795 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
796 * When this function is invoked on the root node of the tree, it destroys the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
797 * tree contents, but - in contrast to #cxTreeFree() - not the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
798 * structure, leaving an empty tree behind.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
799 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
800 * @note The destructor function, if any, will @em not be invoked. That means
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
801 * you will need to free the removed subtree by yourself, eventually.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
802 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
803 * @attention This function will not free the memory of the nodes with the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
804 * tree's allocator, because that is usually done by the advanced destructor
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
805 * and would therefore result in a double-free.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
806 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
807 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
808 * @param node the node to remove
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
809 * @see cxTreeFree()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
810 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
811 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
812 CX_EXPORT void cxTreeDestroySubtree(CxTree *tree, void *node);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
813
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
814
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
815 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
816 * Destroys the tree contents.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
817 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
818 * It is guaranteed that the simple destructor is invoked before
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
819 * the advanced destructor, starting with the leaf nodes of the subtree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
820 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
821 * This is a convenience macro for invoking #cxTreeDestroySubtree() on the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
822 * root node of the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
823 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
824 * @attention Be careful when calling this function when no destructor function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
825 * is registered that actually frees the memory of nodes. In that case you will
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
826 * need a reference to the (former) root node of the tree somewhere, or
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
827 * otherwise you will be leaking memory.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
828 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
829 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
830 * @see cxTreeDestroySubtree()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
831 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
832 #define cxTreeClear(tree) cxTreeDestroySubtree(tree, tree->root)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
833
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
834 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
835 * Deallocates the tree structure.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
836 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
837 * The destructor functions are invoked for each node, starting with the leaf
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
838 * nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
839 * It is guaranteed that for each node the simple destructor is invoked before
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
840 * the advanced destructor.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
841 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
842 * @attention This function will only invoke the destructor functions
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
843 * on the nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
844 * It will NOT additionally free the nodes with the tree's allocator, because
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
845 * that would cause a double-free in most scenarios where the advanced
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
846 * destructor is already freeing the memory.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
847 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
848 * @param tree the tree to free
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
849 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
850 CX_EXPORT void cxTreeFree(CxTree *tree);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
851
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
852 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
853 * Creates a new tree structure based on the specified layout.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
854 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
855 * The specified @p allocator will be used for creating the tree struct
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
856 * and SHALL be used by @p create_func to allocate memory for the nodes.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
857 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
858 * @note This function will also register an advanced destructor which
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
859 * will free the nodes with the allocator's free() method.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
860 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
861 * @param allocator the allocator that shall be used
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
862 * (if @c NULL, the cxDefaultAllocator will be used)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
863 * @param create_func a function that creates new nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
864 * @param search_func a function that compares two nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
865 * @param search_data_func a function that compares a node with data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
866 * @param loc_parent offset in the node struct for the parent pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
867 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
868 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
869 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
870 * @param loc_prev optional offset in the node struct for the prev pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
871 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
872 * @return the new tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
873 * @see cxTreeCreateSimple()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
874 * @see cxTreeCreateWrapped()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
875 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
876 cx_attr_nonnull_arg(2, 3, 4) cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxTreeFree, 1)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
877 CX_EXPORT CxTree *cxTreeCreate(const CxAllocator *allocator, cx_tree_node_create_func create_func,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
878 cx_tree_search_func search_func, cx_tree_search_data_func search_data_func,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
879 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
880 ptrdiff_t loc_prev, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
881
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
882 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
883 * Creates a new tree structure based on a default layout.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
884 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
885 * Nodes created by @p create_func MUST contain #cx_tree_node_base_s as the first
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
886 * member (or at least respect the default offsets specified in the tree
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
887 * struct), and they MUST be allocated with the specified allocator.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
888 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
889 * @note This function will also register an advanced destructor which
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
890 * will free the nodes with the allocator's free() method.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
891 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
892 * @param allocator (@c CxAllocator*) the allocator that shall be used
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
893 * @param create_func (@c cx_tree_node_create_func) a function that creates new nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
894 * @param search_func (@c cx_tree_search_func) a function that compares two nodes
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
895 * @param search_data_func (@c cx_tree_search_data_func) a function that compares a node with data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
896 * @return (@c CxTree*) the new tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
897 * @see cxTreeCreate()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
898 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
899 #define cxTreeCreateSimple(allocator, create_func, search_func, search_data_func) \
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
900 cxTreeCreate(allocator, create_func, search_func, search_data_func, cx_tree_node_base_layout)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
901
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
902 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
903 * Creates a new tree structure based on an existing tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
904 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
905 * The specified @p allocator will be used for creating the tree struct.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
906 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
907 * @attention This function will create an incompletely defined tree structure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
908 * where neither the create function, the search function, nor a destructor
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
909 * will be set. If you wish to use any of this functionality for the wrapped
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
910 * tree, you need to specify those functions afterward.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
911 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
912 * @param allocator the allocator that was used for nodes of the wrapped tree
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
913 * (if @c NULL, the cxDefaultAllocator is assumed)
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
914 * @param root the root node of the tree that shall be wrapped
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
915 * @param loc_parent offset in the node struct for the parent pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
916 * @param loc_children offset in the node struct for the children linked list
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
917 * @param loc_last_child optional offset in the node struct for the pointer to
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
918 * the last child in the linked list (negative if there is no such pointer)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
919 * @param loc_prev optional offset in the node struct for the prev pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
920 * @param loc_next offset in the node struct for the next pointer
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
921 * @return the new tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
922 * @see cxTreeCreate()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
923 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
924 cx_attr_nonnull_arg(2) cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxTreeFree, 1)
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
925 CX_EXPORT CxTree *cxTreeCreateWrapped(const CxAllocator *allocator, void *root,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
926 ptrdiff_t loc_parent, ptrdiff_t loc_children, ptrdiff_t loc_last_child,
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
927 ptrdiff_t loc_prev, ptrdiff_t loc_next);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
928
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
929 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
930 * Inserts data into the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
931 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
932 * @remark For this function to work, the tree needs specified search and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
933 * create functions, which might not be available for wrapped trees
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
934 * (see #cxTreeCreateWrapped()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
935 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
936 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
937 * @param data the data to insert
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
938 * @retval zero success
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
939 * @retval non-zero failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
940 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
941 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
942 CX_EXPORT int cxTreeInsert(CxTree *tree, const void *data);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
943
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
944 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
945 * Inserts elements provided by an iterator efficiently into the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
946 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
947 * @remark For this function to work, the tree needs specified search and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
948 * create functions, which might not be available for wrapped trees
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
949 * (see #cxTreeCreateWrapped()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
950 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
951 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
952 * @param iter the iterator providing the elements
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
953 * @param n the maximum number of elements to insert
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
954 * @return the number of elements that could be successfully inserted
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
955 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
956 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
957 CX_EXPORT size_t cxTreeInsertIter(CxTree *tree, CxIteratorBase *iter, size_t n);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
958
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
959 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
960 * Inserts an array of data efficiently into the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
961 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
962 * @remark For this function to work, the tree needs specified search and
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
963 * create functions, which might not be available for wrapped trees
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
964 * (see #cxTreeCreateWrapped()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
965 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
966 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
967 * @param data the array of data to insert
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
968 * @param elem_size the size of each element in the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
969 * @param n the number of elements in the array
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
970 * @return the number of elements that could be successfully inserted
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
971 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
972 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
973 CX_EXPORT size_t cxTreeInsertArray(CxTree *tree, const void *data, size_t elem_size, size_t n);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
974
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
975 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
976 * Searches the data in the specified tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
977 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
978 * @remark For this function to work, the tree needs a specified @c search_data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
979 * function, which might not be available wrapped trees
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
980 * (see #cxTreeCreateWrapped()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
981 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
982 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
983 * @param data the data to search for
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
984 * @return the first matching node, or @c NULL when the data cannot be found
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
985 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
986 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
987 CX_EXPORT void *cxTreeFind(CxTree *tree, const void *data);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
988
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
989 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
990 * Searches the data in the specified subtree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
991 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
992 * When @p max_depth is zero, the depth is not limited.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
993 * The @p subtree_root itself is on depth 1 and its children have depth 2.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
994 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
995 * @note When @p subtree_root is not part of the @p tree, the behavior is
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
996 * undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
997 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
998 * @remark For this function to work, the tree needs a specified @c search_data
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
999 * function, which might not be the case for wrapped trees
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1000 * (see #cxTreeCreateWrapped()).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1001 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1002 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1003 * @param data the data to search for
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1004 * @param subtree_root the node where to start
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1005 * @param max_depth the maximum search depth
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1006 * @return the first matching node, or @c NULL when the data cannot be found
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1007 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1008 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1009 CX_EXPORT void *cxTreeFindInSubtree(CxTree *tree, const void *data, void *subtree_root, size_t max_depth);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1010
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1011 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1012 * Determines the size of the specified subtree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1013 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1014 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1015 * @param subtree_root the root node of the subtree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1016 * @return the number of nodes in the specified subtree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1017 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1018 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1019 CX_EXPORT size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1020
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1021 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1022 * Determines the depth of the specified subtree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1023 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1024 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1025 * @param subtree_root the root node of the subtree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1026 * @return the tree depth including the @p subtree_root
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1027 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1028 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1029 CX_EXPORT size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root);
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1030
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1031 /**
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1032 * Determines the size of the entire tree.
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1033 *
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1034 * @param tree the tree
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1035 * @return the tree size, counting the root as one
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1036 */
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1037 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1038 CX_EXPORT size_t cxTreeSize(CxTree *tree);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1039
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1040 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1041 * Determines the depth of the entire tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1042 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1043 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1044 * @return the tree depth, counting the root as one
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1045 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1046 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1047 CX_EXPORT size_t cxTreeDepth(CxTree *tree);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1048
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1049 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1050 * Creates a depth-first iterator for the specified tree starting in @p node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1051 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1052 * If the node is not part of the tree, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1053 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1054 * @param tree the tree to iterate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1055 * @param node the node where to start
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1056 * @param visit_on_exit true, if the iterator shall visit a node again when
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1057 * leaving the subtree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1058 * @return a tree iterator (depth-first)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1059 * @see cxTreeVisit()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1060 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1061 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1062 CX_EXPORT CxTreeIterator cxTreeIterateSubtree(CxTree *tree, void *node, bool visit_on_exit);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1063
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1064 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1065 * Creates a breadth-first iterator for the specified tree starting in @p node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1066 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1067 * If the node is not part of the tree, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1068 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1069 * @param tree the tree to iterate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1070 * @param node the node where to start
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1071 * @return a tree visitor (a.k.a. breadth-first iterator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1072 * @see cxTreeIterate()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1073 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1074 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1075 CX_EXPORT CxTreeVisitor cxTreeVisitSubtree(CxTree *tree, void *node);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1076
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1077 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1078 * Creates a depth-first iterator for the specified tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1079 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1080 * @param tree the tree to iterate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1081 * @param visit_on_exit true, if the iterator shall visit a node again when
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1082 * leaving the subtree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1083 * @return a tree iterator (depth-first)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1084 * @see cxTreeVisit()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1085 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1086 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1087 CX_EXPORT CxTreeIterator cxTreeIterate(CxTree *tree, bool visit_on_exit);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1088
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1089 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1090 * Creates a breadth-first iterator for the specified tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1091 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1092 * @param tree the tree to iterate
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1093 * @return a tree visitor (a.k.a. breadth-first iterator)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1094 * @see cxTreeIterate()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1095 */
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1096 cx_attr_nonnull cx_attr_nodiscard
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1097 CxTreeVisitor cxTreeVisit(CxTree *tree);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1098
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1099 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1100 * Sets the (new) parent of the specified child.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1101 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1102 * If the @p child is not already a member of the tree, this function behaves
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1103 * as #cxTreeAddChildNode().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1104 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1105 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1106 * @param parent the (new) parent of the child
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1107 * @param child the node to add
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1108 * @see cxTreeAddChildNode()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1109 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1110 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1111 CX_EXPORT void cxTreeSetParent(CxTree *tree, void *parent, void *child);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1112
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1113 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1114 * Adds a new node to the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1115 *
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1116 * If the @p child is already a member of the tree, the behavior is undefined.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1117 * Use #cxTreeSetParent() if you want to move a subtree to another location.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1118 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1119 * @attention The node may be externally created, but MUST obey the same rules
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1120 * as if it was created by the tree itself with #cxTreeAddChild() (e.g., use
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1121 * the same allocator).
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1122 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1123 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1124 * @param parent the parent of the node to add
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1125 * @param child the node to add
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1126 * @see cxTreeSetParent()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1127 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1128 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1129 CX_EXPORT void cxTreeAddChildNode(CxTree *tree, void *parent, void *child);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1130
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1131 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1132 * Creates a new node and adds it to the tree.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1133 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1134 * With this function you can decide where exactly the new node shall be added.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1135 * If you specified an appropriate search function, you may want to consider
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1136 * leaving this task to the tree by using #cxTreeInsert().
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1137 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1138 * Be aware that adding nodes at arbitrary locations in the tree might cause
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1139 * wrong or undesired results when subsequently invoking #cxTreeInsert(), and
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1140 * the invariant imposed by the search function does not hold any longer.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1141 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1142 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1143 * @param parent the parent node of the new node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1144 * @param data the data that will be submitted to the create function
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1145 * @return zero when the new node was created, non-zero on allocation failure
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1146 * @see cxTreeInsert()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1147 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1148 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1149 CX_EXPORT int cxTreeAddChild(CxTree *tree, void *parent, const void *data);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1150
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1151 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1152 * A function that is invoked when a node needs to be re-linked to a new parent.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1153 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1154 * When a node is re-linked, sometimes the contents need to be updated.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1155 * This callback is invoked by #cxTreeRemoveNode() and #cxTreeDestroyNode()
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1156 * so that those updates can be applied when re-linking the children of the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1157 * removed node.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1158 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1159 * @param node the affected node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1160 * @param old_parent the old parent of the node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1161 * @param new_parent the new parent of the node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1162 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1163 typedef void (*cx_tree_relink_func)(
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1164 void *node,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1165 const void *old_parent,
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1166 const void *new_parent
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1167 );
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1168
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1169 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1170 * Removes a node and re-links its children to its former parent.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1171 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1172 * If the node is not part of the tree, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1173 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1174 * @note The destructor function, if any, will @em not be invoked. That means
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1175 * you will need to free the removed node by yourself, eventually.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1176 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1177 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1178 * @param node the node to remove (must not be the root node)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1179 * @param relink_func optional callback to update the content of each re-linked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1180 * node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1181 * @return zero on success, non-zero if @p node is the root node of the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1182 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1183 cx_attr_nonnull_arg(1, 2)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1184 CX_EXPORT int cxTreeRemoveNode(CxTree *tree, void *node, cx_tree_relink_func relink_func);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1185
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1186 /**
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1187 * Removes a node and its subtree from the tree.
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1188 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1189 * If the node is not part of the tree, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1190 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1191 * @note The destructor function, if any, will @em not be invoked. That means
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1192 * you will need to free the removed subtree by yourself, eventually.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1193 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1194 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1195 * @param node the node to remove
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1196 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1197 cx_attr_nonnull
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1198 CX_EXPORT void cxTreeRemoveSubtree(CxTree *tree, void *node);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1199
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1200 /**
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1201 * Destroys a node and re-links its children to its former parent.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1202 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1203 * If the node is not part of the tree, the behavior is undefined.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1204 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1205 * It is guaranteed that the simple destructor is invoked before
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1206 * the advanced destructor.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1207 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1208 * @attention This function will not free the memory of the node with the
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1209 * tree's allocator, because that is usually done by the advanced destructor
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1210 * and would therefore result in a double-free.
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1211 *
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1212 * @param tree the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1213 * @param node the node to destroy (must not be the root node)
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1214 * @param relink_func optional callback to update the content of each re-linked
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1215 * node
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1216 * @return zero on success, non-zero if @p node is the root node of the tree
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1217 */
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1218 cx_attr_nonnull_arg(1, 2)
888
af685cc9d623 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 854
diff changeset
1219 CX_EXPORT int cxTreeDestroyNode(CxTree *tree, void *node, cx_tree_relink_func relink_func);
852
83fdf679df99 update ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
1220
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1221 #ifdef __cplusplus
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1222 } // extern "C"
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1223 #endif
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1224
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 747
diff changeset
1225 #endif //UCX_TREE_H

mercurial