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

This commit is contained in:
Gregory Lirent 2023-03-26 12:20:22 +03:00 committed by Gogs
commit 9171088b18
2 changed files with 58 additions and 53 deletions

View File

@ -3,21 +3,25 @@
#include "include.h"
bool libcdsb_map_update(map_t* x, vtype_variable key, vtype_variable value, void* dt, map_access_callback callback) {
bool libcdsb_map_update(map_t* x, var_t key, var_t value, void* dt, map_access_callback callback) {
int cmp;
mnode_t* n;
mnode_t* p;
vtype_variable k;
vnode_t kn;
var_t k;
kn = vnode_create_ex(x->type, key);
key = vnode_peek(&kn, x->type);
if (!mnode_is_empty(n = x->root)) {
do {
p = n;
k = vnode_peek(&n->key, x->type);
cmp = variable_compare(key, k);
cmp = variable_compare(key, k = vnode_peek(&n->key, x->type));
if (cmp == 0) {
if (callback) callback(k, vnode_peek(&n->value, n->type), dt);
vnode_free(&kn, x->type);
vnode_free(&n->value, n->type);
n->value = vnode_create(value);
@ -29,7 +33,7 @@ bool libcdsb_map_update(map_t* x, vtype_variable key, vtype_variable value, void
n = (cmp < 0) ? n->left : n->right;
} while (!mnode_is_empty(n));
n = mnode_create(nullptr, p, 1);
n = mnode_create(kn, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
@ -37,9 +41,8 @@ bool libcdsb_map_update(map_t* x, vtype_variable key, vtype_variable value, void
if (!mnode_is_root(p))
mnode_fixup(&x->root, n);
} else n = x->root = mnode_create(nullptr, mnode_empty, 0);
} else n = x->root = mnode_create(kn, mnode_empty, 0);
n->key = vnode_create_ex(x->type, key);
n->value = vnode_create(value);
n->type = value.type;
@ -47,18 +50,17 @@ bool libcdsb_map_update(map_t* x, vtype_variable key, vtype_variable value, void
}
bool libcdsb_map_inject(map_t* x, vtype_variable key, vtype_variable value, void* dt, map_access_callback callback) {
bool libcdsb_map_inject(map_t* x, var_t key, var_t value, void* dt, map_access_callback callback) {
int cmp;
mnode_t* n;
mnode_t* p;
vnode_t kn;
vtype_variable k;
var_t k;
vnode_attach_ex(&kn, x->type, key);
n = x->root;
key = vnode_peek(&kn, x->type);
if (!mnode_is_empty(n)) {
if (!mnode_is_empty(n = x->root)) {
do {
k = vnode_peek(&n->key, x->type);
p = n;

View File

@ -5,62 +5,29 @@
#include "../__internal/rbtree.h"
#include "../__internal/assert.h"
bool libcdsb_vset_insert(set_t* x, vtype_variable value) {
bool libcdsb_vset_insert(set_t* x, var_t value) {
int cmp;
rbnode_t* n;
rbnode_t* p;
vnode_t v;
v = vnode_create_ex(x->type, value);
value = vnode_peek(&v, x->type);
if (!rbnode_is_empty(n = x->root)) {
do {
p = n;
cmp = variable_compare(value, vnode_peek(&n->value, x->type));
if (cmp == 0) return false;
n = (cmp < 0) ? n->left : n->right;
} while (!rbnode_is_empty(n));
n = rbnode_create(nullptr, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
if (!rbnode_is_root(p))
rbnode_fixup(&x->root, n);
} else n = x->root = rbnode_create(nullptr, rbnode_empty, 0);
n->value = vnode_create_ex(x->type, value);
return true;
}
bool libcdsb_vset_attach(set_t* x, vtype_variable value) {
int cmp;
rbnode_t* n;
rbnode_t* p;
vnode_t vn;
vnode_attach_ex(&vn, x->type, value);
n = x->root;
value.type = x->type;
value.pointer = vnode_peek(&vn, value.type).pointer;
if (!rbnode_is_empty(n)) {
do {
p = n;
cmp = variable_compare(value, vnode_peek(&n->value, x->type));
if (cmp == 0) {
vnode_free(&vn, value.type);
vnode_free(&v, x->type);
return false;
}
n = (cmp < 0) ? n->left : n->right;
} while (!rbnode_is_empty(n));
n = rbnode_create(vn, p, 1);
n = rbnode_create(v, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
@ -68,7 +35,43 @@ bool libcdsb_vset_attach(set_t* x, vtype_variable value) {
if (!rbnode_is_root(p))
rbnode_fixup(&x->root, n);
} else n = x->root = rbnode_create(vn, rbnode_empty, 0);
} else n = x->root = rbnode_create(v, rbnode_empty, 0);
return true;
}
bool libcdsb_vset_attach(set_t* x, var_t value) {
int cmp;
rbnode_t* n;
rbnode_t* p;
vnode_t v;
vnode_attach_ex(&v, x->type, value);
value = vnode_peek(&v, x->type);
if (!rbnode_is_empty(n = x->root)) {
do {
p = n;
cmp = variable_compare(value, vnode_peek(&n->value, x->type));
if (cmp == 0) {
vnode_free(&v, value.type);
return false;
}
n = (cmp < 0) ? n->left : n->right;
} while (!rbnode_is_empty(n));
n = rbnode_create(v, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
if (!rbnode_is_root(p))
rbnode_fixup(&x->root, n);
} else n = x->root = rbnode_create(v, rbnode_empty, 0);
return true;
}