134 UcxAllocator *al = tree->allocator; |
134 UcxAllocator *al = tree->allocator; |
135 ucx_avl_free_node(al, tree->root); |
135 ucx_avl_free_node(al, tree->root); |
136 alfree(al, tree); |
136 alfree(al, tree); |
137 } |
137 } |
138 |
138 |
|
139 static void ucx_avl_free_content_node(UcxAllocator *al, UcxAVLNode *node, |
|
140 ucx_destructor destr) { |
|
141 if (node) { |
|
142 ucx_avl_free_content_node(al, node->left, destr); |
|
143 ucx_avl_free_content_node(al, node->right, destr); |
|
144 if (destr) { |
|
145 destr(node->value); |
|
146 } else { |
|
147 alfree(al, node->value); |
|
148 } |
|
149 } |
|
150 } |
|
151 |
|
152 void ucx_avl_free_content(UcxAVLTree *tree, ucx_destructor destr) { |
|
153 ucx_avl_free_content_node(tree->allocator, tree->root, destr); |
|
154 } |
|
155 |
139 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key) { |
156 UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key) { |
140 UcxAVLNode *n = tree->root; |
157 UcxAVLNode *n = tree->root; |
141 int cmpresult; |
158 int cmpresult; |
142 while (n && (cmpresult = tree->cmpfunc( |
159 while (n && (cmpresult = tree->cmpfunc( |
143 ptrcast(key), ptrcast(n->key), tree->userdata))) { |
160 ptrcast(key), ptrcast(n->key), tree->userdata))) { |