From 25eeac41e0088307231cc0c1831d2c1a08cacd0f Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Tue, 15 Apr 1997 04:45:26 +0000 Subject: [PATCH] (update_interval): New function. --- src/intervals.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/intervals.c b/src/intervals.c index cff718d1f8e..744128b84dc 100644 --- a/src/intervals.c +++ b/src/intervals.c @@ -670,6 +670,45 @@ previous_interval (interval) 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 -- 2.39.5