1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 #ifndef UCX_AVL_H
43 #define UCX_AVL_H
44
45 #include "ucx.h"
46 #include "allocator.h"
47 #include <inttypes.h>
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53
54
55
56
57
58 typedef struct UcxAVLNode UcxAVLNode;
59
60
61
62
63 struct UcxAVLNode {
64
65
66
67 intptr_t key;
68
69
70
71 void *value;
72
73
74
75 size_t height;
76
77
78
79 UcxAVLNode *parent;
80
81
82
83 UcxAVLNode *left;
84
85
86
87 UcxAVLNode *right;
88 };
89
90
91
92
93 typedef struct {
94
95
96
97 UcxAllocator *allocator;
98
99
100
101 UcxAVLNode *root;
102
103
104
105
106 cmp_func cmpfunc;
107
108
109
110
111 void *userdata;
112 } UcxAVLTree;
113
114
115
116
117
118
119
120
121 UcxAVLTree *ucx_avl_new(cmp_func cmpfunc);
122
123
124
125
126
127
128
129
130
131
132
133
134 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
135
136
137
138
139
140 void ucx_avl_free(UcxAVLTree *tree);
141
142
143
144
145
146
147
148 #define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator())
149
150
151
152
153
154
155
156 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree,
intptr_t key);
157
158
159
160
161
162
163
164 void *ucx_avl_get(UcxAVLTree *tree,
intptr_t key);
165
166
167
168
169
170
171
172
173
174
175
176
177 int ucx_avl_put(UcxAVLTree *tree,
intptr_t key,
void *value);
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 int ucx_avl_put_s(UcxAVLTree *tree,
intptr_t key,
void *value,
void **oldvalue);
193
194
195
196
197
198
199
200
201
202
203
204
205 int ucx_avl_remove_node(UcxAVLTree *tree, UcxAVLNode *node);
206
207
208
209
210
211
212
213
214 int ucx_avl_remove(UcxAVLTree *tree,
intptr_t key);
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 int ucx_avl_remove_s(UcxAVLTree *tree,
intptr_t key,
235 intptr_t *oldkey,
void **oldvalue);
236
237
238
239
240
241
242 size_t ucx_avl_count(UcxAVLTree *tree);
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif
249
250