5#define _REDBLACK_PRINT(x) std::cout << x << std::endl;
52 _REDBLACK_PRINT(
"==============================================================" << std::endl <<
"ENTER: search(Interval i) : (" << i.
min() <<
", " << i.
max() <<
")" )
60 _REDBLACK_PRINT(
"(" << x->
data <<
": " << x->
key() <<
", " << x->
high() <<
" : " << x->
subtree_max <<
") "
61 <<
" i do not overlap with x")
70 _REDBLACK_PRINT(
"RETURN: search" << std::endl )
77 _REDBLACK_PRINT(
"==============================================================" << std::endl <<
"ENTER: insert(Rect, int, dimension): " <<
" dimension:" << dimension <<
" shape:" << shape )
79 _REDBLACK_PRINT(
"RETURN: insert(Rect, int, dimension)")
84 _REDBLACK_PRINT( std::endl <<
"ENTER: insert(Coord, Coord, int): " << dimension_min <<
", " << dimension_max <<
" , shape: " << shape )
91 _REDBLACK_PRINT(
" x: " << x <<
" KEY: " << x->
key() <<
" high: " << x->
high() )
97 _REDBLACK_PRINT(
" Begin coloring" )
99 _REDBLACK_PRINT(
" while( x!= root && (x->parent)->isRed )" )
101 _REDBLACK_PRINT(
" ((x->parent)->parent)->left:" << ((x->
parent)->parent)->left <<
" ((x->parent)->parent)->right:" << ((x->
parent)->parent)->right )
104 _REDBLACK_PRINT(
" Left:" )
113 _REDBLACK_PRINT(
" y==0" )
118 (x->
parent)->isRed =
false;
123 _REDBLACK_PRINT(
" y->isRed" )
124 (x->
parent)->isRed =
false;
130 _REDBLACK_PRINT(
" !( y->isRed)" )
135 (x->
parent)->isRed =
false;
141 _REDBLACK_PRINT(
" Right:" )
150 _REDBLACK_PRINT(
" y==0" )
155 (x->
parent)->isRed =
false;
160 _REDBLACK_PRINT(
" y->isRed" )
161 (x->
parent)->isRed =
false;
167 _REDBLACK_PRINT(
" !( y->isRed)" )
172 (x->
parent)->isRed =
false;
182 _REDBLACK_PRINT(
" Update max" )
186 _REDBLACK_PRINT(
"RETURN: insert(Coord, Coord, int)" << std::endl)
193 _REDBLACK_PRINT(
"ENTER: left_rotate" )
217 _REDBLACK_PRINT(
"RETURN: left_rotate" << std::endl )
225 _REDBLACK_PRINT(
"ENTER: right_rotate" )
228 _REDBLACK_PRINT(
"x->left: " << x->
left )
251 _REDBLACK_PRINT(
"RETURN: right_rotate" << std::endl )
257 _REDBLACK_PRINT(
"ENTER: tree_insert(RedBlack* z)" )
262 _REDBLACK_PRINT(
" while x!=0 " )
266 _REDBLACK_PRINT(
" z->key: " << z->
key() <<
" y->key: " << y->
key() <<
" compare")
267 if( z->
key() < x->
key() ){
268 _REDBLACK_PRINT(
" z smaller: go left" )
272 _REDBLACK_PRINT(
" z bigger: go right" )
277 _REDBLACK_PRINT(
" z->parent = y" )
281 _REDBLACK_PRINT(
" set z root (empty tree)" )
285 _REDBLACK_PRINT(
" z->key: " << z->
key() <<
" y->key: " << y->
key() <<
" compare")
286 if( z->
key() < y->
key() ){
287 _REDBLACK_PRINT(
" z->key() smaller: y->left = z; " )
291 _REDBLACK_PRINT(
" z->key() bigger: y->right = z " )
295 _REDBLACK_PRINT(
"RETURN: tree_insert(RedBlack* z)" << std::endl )
321 _REDBLACK_PRINT(
"==============================================================" << std::endl <<
"ENTER: earse(z)" )
363 if( y->
isRed ==
false){
367 _REDBLACK_PRINT(
"Update max" )
370 _REDBLACK_PRINT(
"RETURN: erase" )
405 if(
w->isRed ==
true){
407 (
w->parent)->isRed =
true;
411 if( (
w->left)->isRed ==
false && (
w->right)->isRed ==
false ){
416 if( (
w->right)->isRed == false ){
417 (
w->left)->isRed =
false;
423 (x->
parent)->isRed =
false;
424 (
w->right)->isRed =
false;
432 if(
w->isRed ==
true){
434 (
w->parent)->isRed =
true;
438 if( (
w->right)->isRed ==
false && (
w->left)->isRed ==
false ){
443 if( (
w->left)->isRed == false ){
444 (
w->right)->isRed =
false;
450 (x->
parent)->isRed =
false;
451 (
w->left)->isRed =
false;
463 std::cout <<
"Print RedBlackTree status:" << std::endl;
475 std::cout<<
"L:(" << (x->
left)->
data <<
", " << (x->
left)->key() <<
") " ;
486 std::cout<<
"R:(" << (x->
right)->
data <<
", "<< (x->
right)->key() <<
") " ;
497 std::cout<<
" ....... !!! Problem " << oops ;
499 std::cout << std::endl;
506 Coord max_left, max_right;
518 max_left = (x->
left)->subtree_max;
522 max_right = DBL_MIN ;
525 max_right = (x->
right)->subtree_max;
530 temp_max = std::max( x->
high(), max_left );
531 temp_max = std::max( temp_max, max_right );
539 _REDBLACK_PRINT(
"==============================================================" << std::endl <<
"ENTER: tree_minimum" )
540 while( x->
left <- 0 ) {
543 _REDBLACK_PRINT(
"RETURN: tree_minimum" << std::endl )
548 _REDBLACK_PRINT(
"==============================================================" << std::endl <<
"ENTER: tree_successor" )
550 _REDBLACK_PRINT(
"RETURN: tree_successor" << std::endl )
554 _REDBLACK_PRINT(
"y->parent: y->parent" )
555 while( y <- 0 && x == y->right ){
559 _REDBLACK_PRINT(
"RETURN: tree_successor" << std::endl )
Range of real numbers that is never empty.
Axis aligned, non-empty rectangle.
void update_max(RedBlack *x)
void left_rotate(RedBlack *x)
void erase_fixup(RedBlack *x)
RedBlack * tree_successor(RedBlack *x)
RedBlack * tree_minimum(RedBlack *x)
void insert(Rect const &r, int shape, int dimension)
RedBlack * search(Rect const &r, int dimension)
void inorder_tree_walk(RedBlack *x)
void right_rotate(RedBlack *x)
void tree_insert(RedBlack *x)
void erase(Rect const &r)
static char const *const parent
double Coord
Floating point type used to store coordinates.
Various utility functions.
MultiDegree< n > max(MultiDegree< n > const &p, MultiDegree< n > const &q)
Returns the maximal degree appearing in the two arguments for each variables.
Piecewise< SBasis > min(SBasis const &f, SBasis const &g)
Return the more negative of the two functions pointwise.
static cairo_user_data_key_t key
Implementation of Red-Black Tree as described in Intorduction to Algorithms.