130 UcxAllocator *al = tree->allocator; |
130 UcxAllocator *al = tree->allocator; |
131 ucx_avl_free_node(al, tree->root); |
131 ucx_avl_free_node(al, tree->root); |
132 alfree(al, tree); |
132 alfree(al, tree); |
133 } |
133 } |
134 |
134 |
135 UcxAVLNode *ucx_avl_getn(UcxAVLTree *tree, intptr_t key) { |
135 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key) { |
136 UcxAVLNode *n = tree->root; |
136 UcxAVLNode *n = tree->root; |
137 int cmpresult; |
137 int cmpresult; |
138 while (n && (cmpresult = tree->cmpfunc( |
138 while (n && (cmpresult = tree->cmpfunc( |
139 ptrcast(key), ptrcast(n->key), tree->userdata))) { |
139 ptrcast(key), ptrcast(n->key), tree->userdata))) { |
140 n = cmpresult > 0 ? n->right : n->left; |
140 n = cmpresult > 0 ? n->right : n->left; |
141 } |
141 } |
142 return n; |
142 return n; |
143 } |
143 } |
144 |
144 |
145 void *ucx_avl_get(UcxAVLTree *tree, intptr_t key) { |
145 void *ucx_avl_get(UcxAVLTree *tree, intptr_t key) { |
146 UcxAVLNode *n = ucx_avl_getn(tree, key); |
146 UcxAVLNode *n = ucx_avl_get_node(tree, key); |
147 return n ? n->value : NULL; |
147 return n ? n->value : NULL; |
148 } |
148 } |
149 |
149 |
150 int ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value) { |
150 int ucx_avl_put(UcxAVLTree *tree, intptr_t key, void *value) { |
151 return ucx_avl_put_s(tree, key, value, NULL); |
151 return ucx_avl_put_s(tree, key, value, NULL); |
204 |
204 |
205 int ucx_avl_remove(UcxAVLTree *tree, intptr_t key) { |
205 int ucx_avl_remove(UcxAVLTree *tree, intptr_t key) { |
206 return ucx_avl_remove_s(tree, key, NULL, NULL); |
206 return ucx_avl_remove_s(tree, key, NULL, NULL); |
207 } |
207 } |
208 |
208 |
209 int ucx_avl_remove_n(UcxAVLTree *tree, UcxAVLNode *node) { |
209 int ucx_avl_remove_node(UcxAVLTree *tree, UcxAVLNode *node) { |
210 return ucx_avl_remove_s(tree, node->key, NULL, NULL); |
210 return ucx_avl_remove_s(tree, node->key, NULL, NULL); |
211 } |
211 } |
212 |
212 |
213 int ucx_avl_remove_s(UcxAVLTree *tree, intptr_t key, |
213 int ucx_avl_remove_s(UcxAVLTree *tree, intptr_t key, |
214 intptr_t *oldkey, void **oldvalue) { |
214 intptr_t *oldkey, void **oldvalue) { |