Fix rbtree rotation
This commit is contained in:
parent
091c9c011e
commit
09acdb5118
17
src/rbtree.c
17
src/rbtree.c
@ -32,19 +32,15 @@ static inline void rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) {
|
|||||||
rbdir_inv(c, d) = rbdir_dir(n, d);
|
rbdir_inv(c, d) = rbdir_dir(n, d);
|
||||||
n->parent = c->parent;
|
n->parent = c->parent;
|
||||||
|
|
||||||
if (!rbnode_is_empty(rbdir_dir(n, d))) {
|
if (!rbnode_is_empty(rbdir_dir(n, d)))
|
||||||
rbdir_dir(n, d)->parent = c;
|
rbdir_dir(n, d)->parent = c;
|
||||||
}
|
|
||||||
|
|
||||||
if (!rbnode_is_root(c)) {
|
if (!rbnode_is_root(c)) {
|
||||||
rbnode_t* p = c->parent;
|
if (c->parent->left == c) c->parent->left = n;
|
||||||
|
else c->parent->right = n;
|
||||||
if (rbdir_dir(p, d) == c) {
|
|
||||||
rbdir_dir(p, d) = n;
|
|
||||||
} else rbdir_inv(c, d) = n;
|
|
||||||
} else *x = n;
|
} else *x = n;
|
||||||
|
|
||||||
rbdir_inv(n, d) = c;
|
rbdir_dir(n, d) = c;
|
||||||
c->parent = n;
|
c->parent = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +198,6 @@ static void delete_fixup(rbnode_t** x, rbnode_t* n) {
|
|||||||
rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** x, rbnode_t* c) {
|
rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** x, rbnode_t* c) {
|
||||||
rbnode_t *n, *t;
|
rbnode_t *n, *t;
|
||||||
int s;
|
int s;
|
||||||
void* v;
|
|
||||||
|
|
||||||
s = c->colored;
|
s = c->colored;
|
||||||
|
|
||||||
@ -269,7 +264,7 @@ void libcdsb_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) {
|
|||||||
p = n->parent;
|
p = n->parent;
|
||||||
gp = p->parent;
|
gp = p->parent;
|
||||||
}
|
}
|
||||||
p->colored = 0;
|
p->colored = 0;
|
||||||
gp->colored = 1;
|
gp->colored = 1;
|
||||||
|
|
||||||
rotate(x, gp, d[0]);
|
rotate(x, gp, d[0]);
|
||||||
@ -346,7 +341,7 @@ void libcdsb_rbtree_iter_reset(rbiter_t* iter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rbnode_t* hhttpc_rbtree_iter_next(rbiter_t* iter) {
|
rbnode_t* libcdsb_rbtree_iter_next(rbiter_t* iter) {
|
||||||
|
|
||||||
rbnode_t* c;
|
rbnode_t* c;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user