]> git.meshlink.io Git - meshlink/commitdiff
Keep track of the number of nodes in a tree.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 21 Oct 2012 15:34:53 +0000 (17:34 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 21 Oct 2012 15:34:53 +0000 (17:34 +0200)
src/splay_tree.c
src/splay_tree.h

index e7d6dbb0d769ecb2d750a430b244f8d77f19080b..07478f2f7ce35fdd2a3e9ecad1954a0344404189 100644 (file)
@@ -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) {
index 88d75164cb04fb42886faed2fa3141d062e97872..8367ce71f7e3b210203693977029c911fb3db22b 100644 (file)
@@ -58,6 +58,8 @@ typedef struct splay_tree_t {
        splay_compare_t compare;
        splay_action_t delete;
 
+       int count;
+
 } splay_tree_t;
 
 /* (De)constructors */