src/ucx/ucx/avl.h

Mon, 24 Aug 2020 17:07:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 24 Aug 2020 17:07:41 +0200
branch
config
changeset 256
19259b6c5cf7
parent 254
4784c14aa639
permissions
-rw-r--r--

replace old server config loader

254
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * @file avl.h
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * AVL tree implementation.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 * This binary search tree implementation allows average O(1) insertion and
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 * removal of elements (excluding binary search time).
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * @author Mike Becker
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 * @author Olaf Wintermann
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #ifndef UCX_AVL_H
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #define UCX_AVL_H
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include "ucx.h"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include "allocator.h"
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include <inttypes.h>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 #ifdef __cplusplus
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 extern "C" {
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 #endif
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 * UCX AVL Node type.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 * @see UcxAVLNode
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 typedef struct UcxAVLNode UcxAVLNode;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 * UCX AVL Node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 struct UcxAVLNode {
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 * The key for this node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 intptr_t key;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 * Data contained by this node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 void *value;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 * The height of this (sub)-tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 size_t height;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 * Parent node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 UcxAVLNode *parent;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 * Root node of left subtree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 UcxAVLNode *left;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 * Root node of right subtree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UcxAVLNode *right;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 };
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 * UCX AVL Tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 typedef struct {
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 * The UcxAllocator that shall be used to manage the memory for node data.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 UcxAllocator *allocator;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 * Root node of the tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UcxAVLNode *root;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 * Compare function that shall be used to compare the UcxAVLNode keys.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 * @see UcxAVLNode.key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 cmp_func cmpfunc;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 * Custom user data.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 * This data will also be provided to the cmpfunc.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 void *userdata;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 } UcxAVLTree;
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 * Initializes a new UcxAVLTree with a default allocator.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 * @param cmpfunc the compare function that shall be used
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 * @return a new UcxAVLTree object
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 * @see ucx_avl_new_a()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 UcxAVLTree *ucx_avl_new(cmp_func cmpfunc);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 * Initializes a new UcxAVLTree with the specified allocator.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 * The cmpfunc should be capable of comparing two keys within this AVL tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 * So if you want to use null terminated strings as keys, you could use the
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 * ucx_cmp_str() function here.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 * @param cmpfunc the compare function that shall be used
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 * @param allocator the UcxAllocator that shall be used
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 * @return a new UcxAVLTree object
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 * Destroys a UcxAVLTree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 * Note, that the contents are not automatically freed.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 * Use may use #ucx_avl_free_content() before calling this function.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 * @param tree the tree to destroy
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 * @see ucx_avl_free_content()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 void ucx_avl_free(UcxAVLTree *tree);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 * Frees the contents of a UcxAVLTree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 * This is a convenience function that iterates over the tree and passes all
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 * values to the specified destructor function.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * If no destructor is specified (<code>NULL</code>), the free() function of
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 * the tree's own allocator is used.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 * You must ensure, that it is valid to pass each value in the map to the same
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 * destructor function.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 * You should free the entire tree afterwards, as the contents will be invalid.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * @param tree for which the contents shall be freed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 * @param destr optional pointer to a destructor function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 * @see ucx_avl_free()
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 void ucx_avl_free_content(UcxAVLTree *tree, ucx_destructor destr);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 * Macro for initializing a new UcxAVLTree with the default allocator and a
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 * ucx_cmp_ptr() compare function.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 * @return a new default UcxAVLTree object
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 #define ucx_avl_default_new() \
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 ucx_avl_new_a(ucx_cmp_ptr, ucx_default_allocator())
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 * Gets the node from the tree, that is associated with the specified key.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * @return the node (or <code>NULL</code>, if the key is not present)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 * Gets the value from the tree, that is associated with the specified key.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 * @return the value (or <code>NULL</code>, if the key is not present)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void *ucx_avl_get(UcxAVLTree *tree, intptr_t key);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 * A mode for #ucx_avl_find_node() with the same behavior as
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 * #ucx_avl_get_node().
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 #define UCX_AVL_FIND_EXACT 0
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 * A mode for #ucx_avl_find_node() finding the node whose key is at least
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 * as large as the specified key.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 #define UCX_AVL_FIND_LOWER_BOUNDED 1
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 * A mode for #ucx_avl_find_node() finding the node whose key is at most
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 * as large as the specified key.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 #define UCX_AVL_FIND_UPPER_BOUNDED 2
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 * A mode for #ucx_avl_find_node() finding the node with a key that is as close
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 * to the specified key as possible. If the key is present, the behavior is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 * like #ucx_avl_get_node(). This mode only returns <code>NULL</code> on
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 * empty trees.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 #define UCX_AVL_FIND_CLOSEST 3
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 * Finds a node within the tree. The following modes are supported:
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 * <ul>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 * <li>#UCX_AVL_FIND_EXACT: the same behavior as #ucx_avl_get_node()</li>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 * <li>#UCX_AVL_FIND_LOWER_BOUNDED: finds the node whose key is at least
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 * as large as the specified key</li>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 * <li>#UCX_AVL_FIND_UPPER_BOUNDED: finds the node whose key is at most
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 * as large as the specified key</li>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 * <li>#UCX_AVL_FIND_CLOSEST: finds the node with a key that is as close to
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 * the specified key as possible. If the key is present, the behavior is
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 * like #ucx_avl_get_node(). This mode only returns <code>NULL</code> on
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 * empty trees.</li>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 * </ul>
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 * The distance function provided MUST agree with the compare function of
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 * the AVL tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 * @param dfnc the distance function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 * @param mode the find mode
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 * @return the node (or <code>NULL</code>, if no node can be found)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 UcxAVLNode *ucx_avl_find_node(UcxAVLTree *tree, intptr_t key,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 distance_func dfnc, int mode);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 * Finds a value within the tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 * See #ucx_avl_find_node() for details.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 * @param dfnc the distance function
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 * @param mode the find mode
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 * @return the value (or <code>NULL</code>, if no value can be found)
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 void *ucx_avl_find(UcxAVLTree *tree, intptr_t key,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 distance_func dfnc, int mode);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 * Puts a key/value pair into the tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 * Attention: use this function only, if a possible old value does not need
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 * to be preserved.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 * @param value the new value
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 * @return zero, if and only if the operation succeeded
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 int ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 * Puts a key/value pair into the tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 * This is a secure function which saves the old value to the variable pointed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 * at by oldvalue.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 * @param value the new value
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 * @param oldvalue optional: a pointer to the location where a possible old
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 * value shall be stored
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 * @return zero, if and only if the operation succeeded
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 int ucx_avl_put_s(UcxAVLTree *tree, intptr_t key, void *value, void **oldvalue);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 * Removes a node from the AVL tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 * Note: the specified node is logically removed. The tree implementation
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 * decides which memory area is freed. In most cases the here provided node
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 * is freed, so its further use is generally undefined.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 * @param node the node to remove
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 * @return zero, if and only if an element has been removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 int ucx_avl_remove_node(UcxAVLTree *tree, UcxAVLNode *node);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 * Removes an element from the AVL tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 * @param key the key
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 * @return zero, if and only if an element has been removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 int ucx_avl_remove(UcxAVLTree *tree, intptr_t key);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 * Removes an element from the AVL tree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 * This is a secure function which saves the old key and value data from node
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 * to the variables at the location of oldkey and oldvalue (if specified), so
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 * they can be freed afterwards (if necessary).
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 * Note: the returned key in oldkey is possibly not the same as the provided
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 * key for the lookup (in terms of memory location).
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 *
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 * @param tree the UcxAVLTree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 * @param key the key of the element to remove
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 * @param oldkey optional: a pointer to the location where the old key shall be
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 * stored
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 * @param oldvalue optional: a pointer to the location where the old value
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 * shall be stored
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 * @return zero, if and only if an element has been removed
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 int ucx_avl_remove_s(UcxAVLTree *tree, intptr_t key,
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 intptr_t *oldkey, void **oldvalue);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 * Counts the nodes in the specified UcxAVLTree.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 * @param tree the AVL tree
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 * @return the node count
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 size_t ucx_avl_count(UcxAVLTree *tree);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 * Finds the in-order predecessor of the given node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 * @param node an AVL node
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 * @return the in-order predecessor of the given node, or <code>NULL</code> if
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 * the given node is the in-order minimum
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 UcxAVLNode* ucx_avl_pred(UcxAVLNode* node);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 /**
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 * Finds the in-order successor of the given node.
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 * @param node an AVL node
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 * @return the in-order successor of the given node, or <code>NULL</code> if
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 * the given node is the in-order maximum
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 UcxAVLNode* ucx_avl_succ(UcxAVLNode* node);
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 #ifdef __cplusplus
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 }
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 #endif
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352 #endif /* UCX_AVL_H */
4784c14aa639 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353

mercurial