src/ucx/avl.h

Tue, 27 Dec 2016 11:16:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 27 Dec 2016 11:16:39 +0100
changeset 130
198ad9d8cec1
parent 99
b9a6af0ae41a
child 135
471e28cca288
permissions
-rw-r--r--

adds ssl protocol configuration

99
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2015 Olaf Wintermann. All rights reserved.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b9a6af0ae41a 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
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 * @file avl.h
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 * AVL tree implementation.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 * This binary search tree implementation allows average O(1) insertion and
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 * removal of elements (excluding binary search time).
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 * @author Mike Becker
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 * @author Olaf Wintermann
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #ifndef UCX_AVL_H
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #define UCX_AVL_H
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include "ucx.h"
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include "allocator.h"
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include <stdint.h>
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 #ifdef __cplusplus
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 extern "C" {
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 #endif
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 * UCX AVL Node type.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 * @see UcxAVLNode
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 typedef struct UcxAVLNode UcxAVLNode;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 * UCX AVL Node.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 struct UcxAVLNode {
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 * The key for this node.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 intptr_t key;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 * Data contained by this node.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 void *value;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 * The height of this (sub)-tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 size_t height;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 * Parent node.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 UcxAVLNode *parent;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 * Root node of left subtree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 UcxAVLNode *left;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 * Root node of right subtree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UcxAVLNode *right;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 };
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 * UCX AVL Tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 typedef struct {
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 /**
b9a6af0ae41a 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.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 UcxAllocator *allocator;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 * Root node of the tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UcxAVLNode *root;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 * Compare function that shall be used to compare the UcxAVLNode keys.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 * @see UcxAVLNode.key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 cmp_func cmpfunc;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 * Custom user data.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 * This data will also be provided to the cmpfunc.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 void *userdata;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 } UcxAVLTree;
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 * Initializes a new UcxAVLTree with a default allocator.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 * @param cmpfunc the compare function that shall be used
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 * @return a new UcxAVLTree object
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 * @see ucx_avl_new_a()
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 UcxAVLTree *ucx_avl_new(cmp_func cmpfunc);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 * Initializes a new UcxAVLTree with the specified allocator.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 *
b9a6af0ae41a 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.
b9a6af0ae41a 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
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 * ucx_strcmp() function here.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 * @param cmpfunc the compare function that shall be used
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 * @param allocator the UcxAllocator that shall be used
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 * @return a new UcxAVLTree object
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 * Destroys an UcxAVLTree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 * @param tree the tree to destroy
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 void ucx_avl_free(UcxAVLTree *tree);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 * Macro for initializing a new UcxAVLTree with the default allocator and a
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 * ucx_ptrcmp() compare function.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 * @return a new default UcxAVLTree object
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 #define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator())
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 * Gets the node from the tree, that is associated with the specified key.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 * @param key the key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 * @return the node (or <code>NULL</code>, if the key is not present)
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 * Gets the value from the tree, that is associated with the specified key.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 * @param key the key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 * @return the value (or <code>NULL</code>, if the key is not present)
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 void *ucx_avl_get(UcxAVLTree *tree, intptr_t key);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 * Puts a key/value pair into the tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 * Attention: use this function only, if a possible old value does not need
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 * to be preserved.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 * @param key the key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 * @param value the new value
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 * @return zero, if and only if the operation succeeded
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 int ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 * Puts a key/value pair into the tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 * This is a secure function which saves the old value to the variable pointed
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 * at by oldvalue.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 * @param key the key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 * @param value the new value
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 * @param oldvalue optional: a pointer to the location where a possible old
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 * value shall be stored
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 * @return zero, if and only if the operation succeeded
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 int ucx_avl_put_s(UcxAVLTree *tree, intptr_t key, void *value, void **oldvalue);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 * Removes a node from the AVL tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 * Note: the specified node is logically removed. The tree implementation
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 * decides which memory area is freed. In most cases the here provided node
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 * is freed, so it's further use is generally undefined.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 * @param node the node to remove
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 * @return zero, if and only if an element has been removed
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 int ucx_avl_remove_node(UcxAVLTree *tree, UcxAVLNode *node);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 * Removes an element from the AVL tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 * @param key the key
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 * @return zero, if and only if an element has been removed
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 int ucx_avl_remove(UcxAVLTree *tree, intptr_t key);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 * Removes an element from the AVL tree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 * This is a secure function which saves the old key and value data from node
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 * to the variables at the location of oldkey and oldvalue (if specified), so
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 * they can be freed afterwards (if necessary).
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 * Note: the returned key in oldkey is possibly not the same as the provided
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 * key for the lookup (in terms of memory location).
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 *
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 * @param tree the UcxAVLTree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 * @param key the key of the element to remove
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 * @param oldkey optional: a pointer to the location where the old key shall be
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 * stored
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 * @param oldvalue optional: a pointer to the location where the old value
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 * shall be stored
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 * @return zero, if and only if an element has been removed
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 int ucx_avl_remove_s(UcxAVLTree *tree, intptr_t key,
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 intptr_t *oldkey, void **oldvalue);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 /**
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 * Counts the nodes in the specified UcxAVLTree.
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 * @param tree the AVL tree
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 * @return the node count
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 size_t ucx_avl_count(UcxAVLTree *tree);
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 #ifdef __cplusplus
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 }
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 #endif
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 #endif /* UCX_AVL_H */
b9a6af0ae41a ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249

mercurial