|
|
|
@ -60,32 +60,31 @@ |
|
|
|
(node2)->parent = (node1)->parent; \ |
|
|
|
} |
|
|
|
|
|
|
|
#define TR_TREE_ROT_RELCHILD_right(node) ((node)->left) |
|
|
|
#define TR_TREE_ROT_RELCHILD_CHILD_right (relChild->right) |
|
|
|
#define TR_TREE_ROT_RELCHILD_left(node) ((node)->right) |
|
|
|
#define TR_TREE_ROT_RELCHILD_CHILD_left (relChild->left) |
|
|
|
|
|
|
|
#define TR_TREE_ROTATE(lr, _this, node) \ |
|
|
|
if (NULL != (node)) { \ |
|
|
|
TR_Tree _node = (node); \ |
|
|
|
TR_Tree relChild = TR_TREE_ROT_RELCHILD_##lr(_node); \ |
|
|
|
TR_Tree relChildLvl2 = TR_TREE_ROT_RELCHILD_##lr(_node)->lr; \ |
|
|
|
relChild->lr = _node; \ |
|
|
|
relChild->parent = _node->parent; \ |
|
|
|
TR_TREE_ROT_RELCHILD_##lr(_node) = relChildLvl2; \ |
|
|
|
if (NULL != relChildLvl2) { \ |
|
|
|
relChildLvl2->parent = _node; \ |
|
|
|
} \ |
|
|
|
if (NULL != _node->parent) { \ |
|
|
|
if (_node->parent->left == _node) { \ |
|
|
|
_node->parent->left = relChild; \ |
|
|
|
} else { \ |
|
|
|
_node->parent->right = relChild; \ |
|
|
|
} \ |
|
|
|
} else { \ |
|
|
|
*(_this) = relChild; \ |
|
|
|
} \ |
|
|
|
_node->parent = relChild; \ |
|
|
|
#define TR_TREE_ROT_RCLD_right(node) ((node)->left) |
|
|
|
#define TR_TREE_ROT_RCLD_left(node) ((node)->right) |
|
|
|
|
|
|
|
#define TR_TREE_ROTATE(lr, root, node) \ |
|
|
|
if (NULL != (node)) { \ |
|
|
|
void * stPar = node->parent; \ |
|
|
|
void * relCld = TR_TREE_ROT_RCLD_##lr(node); \ |
|
|
|
void * relCCld = TR_TREE_ROT_RCLD_##lr(node)->lr; \ |
|
|
|
void * nLeft_p = &TR_TREE_ROT_RCLD_##lr(node); \ |
|
|
|
if (NULL != relCCld) { \ |
|
|
|
TR_TREE_ROT_RCLD_##lr(node)->lr->parent = node; \ |
|
|
|
} \ |
|
|
|
TR_TREE_ROT_RCLD_##lr(node)->lr = node; \ |
|
|
|
if (NULL != node->parent) { \ |
|
|
|
if (node->parent->left == node) { \ |
|
|
|
node->parent->left = relCld; \ |
|
|
|
} else { \ |
|
|
|
node->parent->right = relCld; \ |
|
|
|
} \ |
|
|
|
} else { \ |
|
|
|
*(root) = relCld; \ |
|
|
|
} \ |
|
|
|
node->parent = relCld; \ |
|
|
|
TR_TREE_ROT_RCLD_##lr(node)->parent = stPar; \ |
|
|
|
*(void**)nLeft_p = relCCld; \ |
|
|
|
} |
|
|
|
|
|
|
|
typedef enum {rbBlack=1, rbRed=2} TR_rbColor; |
|
|
|
|