Mon, 18 May 2015 19:49:03 +0200
added ucx_avl_count
ucx/avl.c | file | annotate | diff | comparison | revisions | |
ucx/avl.h | file | annotate | diff | comparison | revisions |
--- a/ucx/avl.c Mon May 18 19:12:32 2015 +0200 +++ b/ucx/avl.c Mon May 18 19:49:03 2015 +0200 @@ -214,3 +214,14 @@ } } +static size_t ucx_avl_countn(UcxAVLNode *node) { + if (node) { + return 1 + ucx_avl_countn(node->left) + ucx_avl_countn(node->right); + } else { + return 0; + } +} + +size_t ucx_avl_count(UcxAVLTree *tree) { + return ucx_avl_countn(tree->root); +}
--- a/ucx/avl.h Mon May 18 19:12:32 2015 +0200 +++ b/ucx/avl.h Mon May 18 19:49:03 2015 +0200 @@ -173,7 +173,12 @@ */ void* ucx_avl_remove(UcxAVLTree *tree, intptr_t key); - +/** + * Counts the nodes in the specified UcxAVLTree. + * @param tree the AVL tree + * @return the node count + */ +size_t ucx_avl_count(UcxAVLTree *tree); #ifdef __cplusplus }