|
|
|
@ -33,14 +33,12 @@ |
|
|
|
(NULL==TR_TREE_RIGHT((node))?TR_TREE_LEFT((node)):TR_TREE_RIGHT((node))) |
|
|
|
|
|
|
|
#define TR_TREE_SIBLING(node) \ |
|
|
|
(NULL!=TR_TREE_PARENT((node))? \ |
|
|
|
((node)==TR_TREE_PARENT((node))->left? \ |
|
|
|
TR_TREE_PARENT((node))->right: \ |
|
|
|
TR_TREE_PARENT((node))->left): \ |
|
|
|
(NULL!=(node)->parent? \ |
|
|
|
((node)==(node)->parent->left? \ |
|
|
|
(node)->parent->right: \ |
|
|
|
(node)->parent->left): \ |
|
|
|
NULL) |
|
|
|
|
|
|
|
#define TR_TREE_GRANDPARENT(node) (TR_TREE_PARENT((node))->parent) |
|
|
|
|
|
|
|
#define TR_TREE_UNCLE(node) \ |
|
|
|
((node)->parent == (node)->parent->parent->left \ |
|
|
|
? (node)->parent->parent->right \ |
|
|
|
@ -130,7 +128,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; |
|
|
|
} |
|
|
|
|
|
|
|
#define TR_TREE_BALANCE_DELETE_CASE1(node) \ |
|
|
|
if (NULL == TR_TREE_PARENT((node))) { \ |
|
|
|
if (NULL == (node)->parent) { \ |
|
|
|
break; \ |
|
|
|
} |
|
|
|
|
|
|
|
@ -216,6 +214,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; |
|
|
|
#define TR_TREE_BALANCE_DELETE(root, node, sibling) \ |
|
|
|
while(1) { \ |
|
|
|
TR_TREE_BALANCE_DELETE_CASE1((node)) \ |
|
|
|
sibling = TR_TREE_SIBLING(node); \ |
|
|
|
TR_TREE_BALANCE_DELETE_CASE2((root), (node), (sibling)) \ |
|
|
|
TR_TREE_BALANCE_DELETE_CASE34((root), (node), (sibling)) \ |
|
|
|
TR_TREE_BALANCE_DELETE_CASE5((root), (node), (sibling)) \ |
|
|
|
@ -224,7 +223,7 @@ typedef enum {rbBlack=1, rbRed=2} TR_rbColor; |
|
|
|
} |
|
|
|
|
|
|
|
#define TR_TREE_BALANCE_INSERT_CASE1(node) \ |
|
|
|
if (NULL == TR_TREE_PARENT((node))) { \ |
|
|
|
if (NULL == (node)->parent) { \ |
|
|
|
(node)->color = rbBlack; \ |
|
|
|
break; \ |
|
|
|
} |
|
|
|
|