void IntervalTree::FixUpMaxHigh(IntervalTreeNode * x) { while(x != root) { x->maxHigh=ITMax(x->high,ITMax(x->left->maxHigh,x->right->maxHigh)); x=x->parent; } #ifdef CHECK_INTERVAL_TREE_ASSUMPTIONS CheckAssumptions(); #endif }
static void FixUpMaxHigh(IntervalTree *it, IntervalTreeNode *x) { while(x != it->root) { x->maxHigh=ITMax(x->high,ITMax(x->left->maxHigh,x->right->maxHigh)); x=x->parent; } #ifdef CHECK_INTERVAL_TREE_ASSUMPTIONS IT_CheckAssumptions(it); #endif }
static void LeftRotate(IntervalTree *it, IntervalTreeNode *x) { IntervalTreeNode *y; /* I originally wrote this function to use the sentinel for * nil to avoid checking for nil. However this introduces a * very subtle bug because sometimes this function modifies * the parent pointer of nil. This can be a problem if a * function which calls LeftRotate also uses the nil sentinel * and expects the nil sentinel's parent pointer to be unchanged * after calling this function. For example, when DeleteFixUP * calls LeftRotate it expects the parent pointer of nil to be * unchanged. */ y=x->right; x->right=y->left; if (y->left != it->nil) y->left->parent=x; /* used to use sentinel here */ /* and do an unconditional assignment instead of testing for nil */ y->parent=x->parent; /* Instead of checking if x->parent is the root as in the book, we * count on the root sentinel to implicitly take care of this case */ if (x == x->parent->left) x->parent->left=y; else x->parent->right=y; y->left=x; x->parent=y; x->maxHigh=ITMax(x->left->maxHigh,ITMax(x->right->maxHigh,x->high)); y->maxHigh=ITMax(x->maxHigh,ITMax(y->right->maxHigh,y->high)); #ifdef CHECK_INTERVAL_TREE_ASSUMPTIONS IT_CheckAssumptions(it); #elif defined(DEBUG_ASSERT) Assert(!it->nil->red,"nil not red in ITLeftRotate"); Assert((it->nil->maxHigh=LONG_MIN), "nil->maxHigh != LONG_MIN in ITLeftRotate"); #endif }
void IntervalTree::RightRotate(IntervalTreeNode* y) { IntervalTreeNode* x; /* I originally wrote this function to use the sentinel for */ /* nil to avoid checking for nil. However this introduces a */ /* very subtle bug because sometimes this function modifies */ /* the parent pointer of nil. This can be a problem if a */ /* function which calls LeftRotate also uses the nil sentinel */ /* and expects the nil sentinel's parent pointer to be unchanged */ /* after calling this function. For example, when DeleteFixUP */ /* calls LeftRotate it expects the parent pointer of nil to be */ /* unchanged. */ x=y->left; y->left=x->right; if (nil != x->right) x->right->parent=y; /*used to use sentinel here */ /* and do an unconditional assignment instead of testing for nil */ /* instead of checking if x->parent is the root as in the book, we */ /* count on the root sentinel to implicitly take care of this case */ x->parent=y->parent; if( y == y->parent->left) { y->parent->left=x; } else { y->parent->right=x; } x->right=y; y->parent=x; y->maxHigh=ITMax(y->left->maxHigh,ITMax(y->right->maxHigh,y->high)); x->maxHigh=ITMax(x->left->maxHigh,ITMax(y->maxHigh,x->high)); #ifdef CHECK_INTERVAL_TREE_ASSUMPTIONS CheckAssumptions(); #elif defined(DEBUG_ASSERT) Assert(!nil->red,"nil not red in ITRightRotate"); Assert((nil->maxHigh=MIN_INT), "nil->maxHigh != MIN_INT in ITRightRotate"); #endif }