changeset 17461:156dd2e14452

(update_interval): New function.
author Richard M. Stallman <rms@gnu.org>
date Tue, 15 Apr 1997 04:45:26 +0000
parents 6923ae3375f7
children a609ccd7eefb
files src/intervals.c
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/intervals.c	Tue Apr 15 04:44:36 1997 +0000
+++ b/src/intervals.c	Tue Apr 15 04:45:26 1997 +0000
@@ -670,6 +670,45 @@
 
   return NULL_INTERVAL;
 }
+
+/* Find the interval containing POS given some non-NULL INTERVAL
+   in the same tree. */
+INTERVAL
+update_interval (i, pos)
+     register INTERVAL i;
+     int pos;
+{
+  if (NULL_INTERVAL_P (i))
+    return NULL_INTERVAL;
+
+  while (1) 
+    {
+      if (pos < i->position) 
+	{
+	  /* Move left. */
+	  if (pos >= i->position - 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;
+	  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 */
+	  else if (NULL_PARENT (i)) 
+	    error ("Point after end of properties");
+	  else 
+	    i = i->parent;
+	  continue;
+	}
+      else 
+	return i;
+    }
+}
+
 
 #if 0
 /* Traverse a path down the interval tree TREE to the interval