Merge branch '#53-issue' of lirent/libcdsb into develop

This commit is contained in:
Gregory Lirent 2022-08-25 21:44:51 +03:00 committed by Gogs
commit 2ee1d73def

View File

@ -196,61 +196,42 @@ void* libcdsb_builtin_rbtree_node_create(void* v, rbnode_t* p, int c, int n) {
stack_t libcdsb_builtin_rbtree_iter_inorder(rbnode_t** root, bool reverse) {
rbnode_t *n, hack;
stack_t z, *bot;
stack_t z, *cur;
rbnode_t *n;
memset(&z, 0, sizeof(z));
if (rbnode_is_empty(*root))
if (rbnode_is_empty(n = *root))
return z;
hack.right = *root;
n = &hack;
for (bot = &z;;) {
for (;;) {
if (rbnode_is_empty(n->right)) {
if (rbnode_is_root(n->parent) || n->parent->left == n) {
n = n->parent;
break;
} else n = n->parent;
if (rbnode_is_root(n->parent) || n->parent->left == n) {
n = n->parent;
break;
while (!rbnode_is_empty(n)) {
stack_insert(&z, n);
n = n->left;
}
do {
n = n->parent;
} while (n->parent->right == n);
cur = z.prev;
z.value = z.prev->value;
z.prev = z.prev->prev;
n = n->parent;
} else {
free(cur);
cur = &z;
while ((cur = cur->prev)) {
n = cur->value;
if (!rbnode_is_empty(n->right)) {
n = n->right;
while (!rbnode_is_empty(n->left))
while (!rbnode_is_empty(n)) {
stack_insert(cur, n);
n = n->left;
break;
}
if (rbnode_is_root(n)) {
bot = z.prev;
z = *bot;
free(bot);
if (reverse)
stack_reverse(&z);
}
}
return z;
}
}
bot = stack_insert(bot, n);
}
}
stack_t libcdsb_builtin_rbtree_iter_preorder(rbnode_t** root, bool reverse) {