Mercurial > emacs
comparison src/intervals.c @ 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 | 5c60cd16452b |
children | 78203467fc7d |
comparison
equal
deleted
inserted
replaced
21011:ceb05db73a63 | 21012:22c48e547cb0 |
---|---|
670 | 670 |
671 return NULL_INTERVAL; | 671 return NULL_INTERVAL; |
672 } | 672 } |
673 | 673 |
674 /* Find the interval containing POS given some non-NULL INTERVAL | 674 /* Find the interval containing POS given some non-NULL INTERVAL |
675 in the same tree. */ | 675 in the same tree. Note that we need to update interval->position |
676 if we go down the tree. */ | |
676 INTERVAL | 677 INTERVAL |
677 update_interval (i, pos) | 678 update_interval (i, pos) |
678 register INTERVAL i; | 679 register INTERVAL i; |
679 int pos; | 680 int pos; |
680 { | 681 { |
684 while (1) | 685 while (1) |
685 { | 686 { |
686 if (pos < i->position) | 687 if (pos < i->position) |
687 { | 688 { |
688 /* Move left. */ | 689 /* Move left. */ |
689 if (pos >= i->position - TOTAL_LENGTH (i->left)) | 690 if (pos >= i->position - TOTAL_LENGTH (i->left)) |
690 i = i->left; /* Move to the left child */ | 691 { |
692 i->left->position = i->position - TOTAL_LENGTH (i->left) | |
693 + LEFT_TOTAL_LENGTH (i->left); | |
694 i = i->left; /* Move to the left child */ | |
695 } | |
691 else if (NULL_PARENT (i)) | 696 else if (NULL_PARENT (i)) |
692 error ("Point before start of properties"); | 697 error ("Point before start of properties"); |
693 else i = i->parent; | 698 else |
699 i = i->parent; | |
694 continue; | 700 continue; |
695 } | 701 } |
696 else if (pos >= INTERVAL_LAST_POS (i)) | 702 else if (pos >= INTERVAL_LAST_POS (i)) |
697 { | 703 { |
698 /* Move right. */ | 704 /* Move right. */ |
699 if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) | 705 if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) |
700 i = i->right; /* Move to the right child */ | 706 { |
707 i->right->position = INTERVAL_LAST_POS (i) + | |
708 LEFT_TOTAL_LENGTH (i->right); | |
709 i = i->right; /* Move to the right child */ | |
710 } | |
701 else if (NULL_PARENT (i)) | 711 else if (NULL_PARENT (i)) |
702 error ("Point after end of properties"); | 712 error ("Point after end of properties"); |
703 else | 713 else |
704 i = i->parent; | 714 i = i->parent; |
705 continue; | 715 continue; |
706 } | 716 } |
707 else | 717 else |
708 return i; | 718 return i; |
709 } | 719 } |