changeset 21012:22c48e547cb0

(update_interval): Properly update `position' field of used intervals.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Mar 1998 02:41:28 +0000
parents ceb05db73a63
children adb28ace7f33
files src/intervals.c
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/intervals.c	Mon Mar 02 02:40:53 1998 +0000
+++ b/src/intervals.c	Mon Mar 02 02:41:28 1998 +0000
@@ -672,7 +672,8 @@
 }
 
 /* Find the interval containing POS given some non-NULL INTERVAL
-   in the same tree. */
+   in the same tree.  Note that we need to update interval->position
+   if we go down the tree.  */
 INTERVAL
 update_interval (i, pos)
      register INTERVAL i;
@@ -686,22 +687,31 @@
       if (pos < i->position) 
 	{
 	  /* Move left. */
-	  if (pos >= i->position - TOTAL_LENGTH (i->left))
-	    i = i->left;		/* Move to the left child */
+	  if (pos >= i->position - TOTAL_LENGTH (i->left)) 
+	    {
+	      i->left->position = i->position - TOTAL_LENGTH (i->left)
+		+ LEFT_TOTAL_LENGTH (i->left);
+	      i = i->left;		/* Move to the left child */
+	    }
 	  else if (NULL_PARENT (i)) 
 	    error ("Point before start of properties");
-	  else  i = i->parent;
+	  else  
+	      i = i->parent;
 	  continue;
 	}
       else if (pos >= INTERVAL_LAST_POS (i))
 	{
 	  /* Move right. */
-	  if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right))
-	    i = i->right;		/* Move to the right child */
+	  if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) 
+	    {
+	      i->right->position = INTERVAL_LAST_POS (i) +
+		LEFT_TOTAL_LENGTH (i->right);
+	      i = i->right;		/* Move to the right child */
+	    }
 	  else if (NULL_PARENT (i)) 
 	    error ("Point after end of properties");
 	  else 
-	    i = i->parent;
+	      i = i->parent;
 	  continue;
 	}
       else