# HG changeset patch # User Mike Becker # Date 1431971343 -7200 # Node ID e25dc68336ec8bd443f0f2cd0a8fe2178b4e0ed6 # Parent b0f4fb043b475168723774f47b436acce9d19e02 added ucx_avl_count diff -r b0f4fb043b47 -r e25dc68336ec ucx/avl.c --- 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); +} diff -r b0f4fb043b47 -r e25dc68336ec ucx/avl.h --- 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 }