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