From 09acdb5118d6a313fd787e43c2b764f42c3f4486 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 6 Jun 2022 23:45:11 +0300 Subject: [PATCH] Fix rbtree rotation --- src/rbtree.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/rbtree.c b/src/rbtree.c index 22dee93..a8681b7 100644 --- a/src/rbtree.c +++ b/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); 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; - } if (!rbnode_is_root(c)) { - rbnode_t* p = c->parent; - - if (rbdir_dir(p, d) == c) { - rbdir_dir(p, d) = n; - } else rbdir_inv(c, d) = n; + if (c->parent->left == c) c->parent->left = n; + else c->parent->right = n; } else *x = n; - rbdir_inv(n, d) = c; + rbdir_dir(n, d) = c; 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 *n, *t; int s; - void* v; s = c->colored; @@ -269,7 +264,7 @@ void libcdsb_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) { p = n->parent; gp = p->parent; } - p->colored = 0; + p->colored = 0; gp->colored = 1; 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;