mirror of https://github.com/PrimeDecomp/prime.git
97% rbtree_rebalance
This commit is contained in:
parent
cb11fd2320
commit
1bb8002205
|
@ -70,40 +70,39 @@ void rbtree_rotate_right(void* header_void, void* node_void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void rbtree_rebalance(void* header_void, void* node_void) {
|
void rbtree_rebalance(void* header_void, void* node_void) {
|
||||||
_header* header = static_cast< _header* >(header_void);
|
|
||||||
_node* node = static_cast< _node* >(node_void);
|
_node* node = static_cast< _node* >(node_void);
|
||||||
_node* it;
|
_header* header = static_cast< _header* >(header_void);
|
||||||
|
|
||||||
while ((it = node->mParent) != nullptr && it->mColor == kNC_Black) {
|
while (node->mParent != nullptr && node->mParent->mColor == kNC_Black) {
|
||||||
_node* p = it->mParent->mLeft;
|
_node* p = node->mParent->mParent->mLeft;
|
||||||
if (it == p) {
|
if (node->mParent == p) {
|
||||||
p = it->mParent->mRight;
|
p = node->mParent->mParent->mRight;
|
||||||
if ((p != nullptr && p->mColor == kNC_Black)) {
|
if ((p != nullptr && p->mColor == kNC_Black)) {
|
||||||
it->mColor = kNC_Red;
|
node->mParent->mColor = kNC_Red;
|
||||||
p->mColor = kNC_Red;
|
p->mColor = kNC_Red;
|
||||||
node->mParent->mParent->mColor = kNC_Black;
|
node->mParent->mParent->mColor = kNC_Black;
|
||||||
node = node->mParent->mParent;
|
node = node->mParent->mParent;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (node == it->mRight) {
|
if (node == node->mParent->mRight) {
|
||||||
rbtree_rotate_left(header, it);
|
rbtree_rotate_left(header, node->mParent);
|
||||||
}
|
}
|
||||||
node = it;
|
// node = node->mParent;
|
||||||
node->mParent->mColor = kNC_Red;
|
node->mParent->mColor = kNC_Red;
|
||||||
node->mParent->mParent->mColor = kNC_Black;
|
node->mParent->mParent->mColor = kNC_Black;
|
||||||
rbtree_rotate_right(header, node->mParent->mParent);
|
rbtree_rotate_right(header, node->mParent->mParent);
|
||||||
}
|
}
|
||||||
} else if (p != nullptr && p->mColor == kNC_Black) {
|
} else if (p != nullptr && p->mColor == kNC_Black) {
|
||||||
it->mColor = kNC_Red;
|
node->mParent->mColor = kNC_Red;
|
||||||
p->mColor = kNC_Red;
|
p->mColor = kNC_Red;
|
||||||
node->mParent->mParent->mColor = kNC_Black;
|
node->mParent->mParent->mColor = kNC_Black;
|
||||||
node = node->mParent->mParent;
|
node = node->mParent->mParent;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (node == it->mLeft) {
|
if (node == node->mParent->mLeft) {
|
||||||
rbtree_rotate_right(header, it);
|
rbtree_rotate_right(header, node->mParent);
|
||||||
}
|
}
|
||||||
node = it;
|
// node = node->mParent;
|
||||||
node->mParent->mColor = kNC_Red;
|
node->mParent->mColor = kNC_Red;
|
||||||
node->mParent->mParent->mColor = kNC_Black;
|
node->mParent->mParent->mColor = kNC_Black;
|
||||||
rbtree_rotate_left(header, node->mParent->mParent);
|
rbtree_rotate_left(header, node->mParent->mParent);
|
||||||
|
|
Loading…
Reference in New Issue