From: Guus Sliepen Date: Sun, 21 Oct 2012 15:34:53 +0000 (+0200) Subject: Keep track of the number of nodes in a tree. X-Git-Tag: release-1.1pre4~33 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=1f8b70efa0dedbd3642e0ee82a640d125664af34;p=tinc Keep track of the number of nodes in a tree. --- diff --git a/src/splay_tree.c b/src/splay_tree.c index e7d6dbb0..07478f2f 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -418,6 +418,7 @@ splay_node_t *splay_insert_node(splay_tree_t *tree, splay_node_t *node) { void splay_insert_top(splay_tree_t *tree, splay_node_t *node) { node->prev = node->next = node->left = node->right = node->parent = NULL; tree->head = tree->tail = tree->root = node; + tree->count++; } void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t *node) { @@ -446,6 +447,7 @@ void splay_insert_before(splay_tree_t *tree, splay_node_t *before, splay_node_t node->parent = NULL; tree->root = node; + tree->count++; } void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *node) { @@ -474,6 +476,7 @@ void splay_insert_after(splay_tree_t *tree, splay_node_t *after, splay_node_t *n node->parent = NULL; tree->root = node; + tree->count++; } splay_node_t *splay_unlink(splay_tree_t *tree, void *data) { @@ -511,6 +514,8 @@ void splay_unlink_node(splay_tree_t *tree, splay_node_t *node) { } else { tree->root = NULL; } + + tree->count--; } void splay_delete_node(splay_tree_t *tree, splay_node_t *node) { diff --git a/src/splay_tree.h b/src/splay_tree.h index 88d75164..8367ce71 100644 --- a/src/splay_tree.h +++ b/src/splay_tree.h @@ -58,6 +58,8 @@ typedef struct splay_tree_t { splay_compare_t compare; splay_action_t delete; + int count; + } splay_tree_t; /* (De)constructors */