[gtk+] rbtree: Use gtk_rbnode_adjust() even more



commit 1dd9dd45c1654f6c13c8eb19f493028636e396b3
Author: Benjamin Otte <otte redhat com>
Date:   Sun Nov 20 21:27:46 2011 +0100

    rbtree: Use gtk_rbnode_adjust() even more
    
    Use it for the modified node in gtk_rbnode_remove(). Cleans up the code
    quite a lot.

 gtk/gtkrbtree.c |   42 +++++++++++++++---------------------------
 1 files changed, 15 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c
index a09db5a..b8f9122 100644
--- a/gtk/gtkrbtree.c
+++ b/gtk/gtkrbtree.c
@@ -1131,9 +1131,8 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
 			 GtkRBNode *node)
 {
   GtkRBNode *x, *y;
-  GtkRBTree *tmp_tree;
-  GtkRBNode *tmp_node;
   gint y_height;
+  guint y_total_count;
   
   g_return_if_fail (tree != NULL);
   g_return_if_fail (node != NULL);
@@ -1170,7 +1169,9 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
 	y = y->left;
     }
 
-  y_height = GTK_RBNODE_GET_HEIGHT (y);
+  y_height = GTK_RBNODE_GET_HEIGHT (y) 
+             + (y->children ? y->children->root->offset : 0);
+  y_total_count = 1 + (y->children ? y->children->root->total_count : 0);
 
   /* x is y's only child, or nil */
   if (y->left != tree->nil)
@@ -1194,13 +1195,19 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
 
   /* We need to clean up the validity of the tree.
    */
-  gtk_rbnode_adjust (tree, y,
-                     -1, -1,
-                     - (y_height + (y->children?y->children->root->offset:0)));
+  gtk_rbnode_adjust (tree, y, -1, - y_total_count, - y_height);
 
   if (y != node)
     {
-      gint diff;
+      gint count_diff, height_diff;
+
+      /* We want to see how different our height is from the previous node.
+       * To do this, we compare our current height with our supposed height.
+       */
+      height_diff = y_height 
+                    - GTK_RBNODE_GET_HEIGHT (node)
+                    - (node->children ? node->children->root->offset : 0);
+      count_diff = y->total_count - node->total_count;
 
       /* Copy the node over */
       if (GTK_RBNODE_GET_COLOR (node) == GTK_RBNODE_BLACK)
@@ -1216,27 +1223,8 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
 	{
 	  node->children = NULL;
 	}
-      _fixup_validation (tree, node);
-      _fixup_total_count (tree, node);
-      /* We want to see how different our height is from the previous node.
-       * To do this, we compare our current height with our supposed height.
-       */
-      diff = y_height - GTK_RBNODE_GET_HEIGHT (node);
-      tmp_tree = tree;
-      tmp_node = node;
 
-      while (tmp_tree && tmp_node && tmp_node != tmp_tree->nil)
-	{
-	  tmp_node->offset += diff;
-	  _fixup_validation (tmp_tree, tmp_node);
-	  _fixup_total_count (tmp_tree, tmp_node);
-	  tmp_node = tmp_node->parent;
-	  if (tmp_node == tmp_tree->nil)
-	    {
-	      tmp_node = tmp_tree->parent_node;
-	      tmp_tree = tmp_tree->parent_tree;
-	    }
-	}
+      gtk_rbnode_adjust (tree, node, 0, count_diff, height_diff);
     }
 
   if (GTK_RBNODE_GET_COLOR (y) == GTK_RBNODE_BLACK)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]