diff -r 62f1a55535e7 -r 0b33b9396851 ucx/avl.c --- a/ucx/avl.c Mon Feb 04 14:46:11 2019 +0100 +++ b/ucx/avl.c Mon Feb 04 17:49:50 2019 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2016 Olaf Wintermann. All rights reserved. + * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -26,9 +26,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include +#include "ucx/avl.h" -#include "avl.h" +#include #define ptrcast(ptr) ((void*)(ptr)) #define alloc_tree(al) (UcxAVLTree*) almalloc((al), sizeof(UcxAVLTree)) @@ -136,6 +136,23 @@ alfree(al, tree); } +static void ucx_avl_free_content_node(UcxAllocator *al, UcxAVLNode *node, + ucx_destructor destr) { + if (node) { + ucx_avl_free_content_node(al, node->left, destr); + ucx_avl_free_content_node(al, node->right, destr); + if (destr) { + destr(node->value); + } else { + alfree(al, node->value); + } + } +} + +void ucx_avl_free_content(UcxAVLTree *tree, ucx_destructor destr) { + ucx_avl_free_content_node(tree->allocator, tree->root, destr); +} + UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree, intptr_t key) { UcxAVLNode *n = tree->root; int cmpresult;