Update map (vtype_variable)
This commit is contained in:
+8
-5
@@ -22,7 +22,8 @@ static int libcdsb_builtin_foreach(map_t* x, void* data, map_access_callback cal
|
||||
if (!mnode_is_empty(n->right)) cur = stack_insert(cur, n->right);
|
||||
|
||||
if (!r) {
|
||||
r = callback(vnode_peek(&n->key, x->type), x->type, vnode_peek(&n->value, n->type), n->type, data);
|
||||
r = callback(libcdsb_variable_build(vnode_peek(&n->key, x->type), x->type),
|
||||
libcdsb_variable_build(vnode_peek(&n->value, n->type), n->type), data);
|
||||
} else {
|
||||
stack_flush(&z);
|
||||
return r;
|
||||
@@ -45,7 +46,7 @@ static int libcdsb_builtin_foreach(map_t* x, void* data, map_access_callback cal
|
||||
|
||||
/*#####################################################################################################################*/
|
||||
|
||||
int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callback callback, bool cut) {
|
||||
int libcdsb_map_find(map_t* x, vtype_variable kvar, void* _, map_access_callback callback, bool cut) {
|
||||
mnode_t* c;
|
||||
void *key;
|
||||
int cmp;
|
||||
@@ -54,10 +55,11 @@ int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callb
|
||||
|
||||
while (!mnode_is_empty(c)) {
|
||||
key = vnode_peek(&c->key, x->type);
|
||||
cmp = vtype_compare(k, t, key, x->type);
|
||||
cmp = vtype_compare(kvar.pointer, kvar.type, key, x->type);
|
||||
|
||||
if (cmp == 0) {
|
||||
cmp = (callback) ? callback(key, x->type, vnode_peek(&c->value, c->type), c->type, _) : 0;
|
||||
cmp = (callback) ? callback(libcdsb_variable_build(key, x->type),
|
||||
libcdsb_variable_build(vnode_peek(&c->value, c->type), c->type), _) : 0;
|
||||
|
||||
if (cut) {
|
||||
c = mnode_delete(&x->root, c);
|
||||
@@ -96,7 +98,8 @@ int libcdsb_map_foreach(map_t* x, void* data, map_access_callback callback, rbfo
|
||||
|
||||
while ((n = stack_pop(&iter))) {
|
||||
if (!r) {
|
||||
r = callback(vnode_peek(&n->key, x->type), x->type, vnode_peek(&n->value, n->type), n->type, data);
|
||||
r = callback(libcdsb_variable_build(vnode_peek(&n->key, x->type), x->type),
|
||||
libcdsb_variable_build(vnode_peek(&n->value, n->type), n->type), data);
|
||||
} else if (!flush) {
|
||||
stack_flush(&iter);
|
||||
return r;
|
||||
|
||||
+17
-18
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "include.h"
|
||||
|
||||
bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype vt, void* dt, map_access_callback callback) {
|
||||
bool libcdsb_map_update(map_t* x, vtype_variable key, vtype_variable value, void* dt, map_access_callback callback) {
|
||||
int cmp;
|
||||
mnode_t* n;
|
||||
mnode_t* p;
|
||||
@@ -11,15 +11,15 @@ bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype
|
||||
if (!mnode_is_empty(n = x->root)) {
|
||||
do {
|
||||
p = n;
|
||||
cmp = vtype_compare(k, kt, vnode_peek(&n->key, kt), kt);
|
||||
cmp = vtype_compare(key.pointer, key.type, vnode_peek(&n->key, key.type), key.type);
|
||||
|
||||
if (cmp == 0) {
|
||||
if (callback) callback(vnode_peek(&n->key, x->type), x->type,
|
||||
vnode_peek(&n->value, n->type), n->type, dt);
|
||||
if (callback) callback(libcdsb_variable_build(vnode_peek(&n->key, x->type), x->type),
|
||||
libcdsb_variable_build(vnode_peek(&n->value, n->type), n->type), dt);
|
||||
|
||||
vnode_free(&n->value, n->type);
|
||||
|
||||
n->value = vnode_create(v, n->type = vt);
|
||||
n->value = vnode_create(value.pointer, n->type = value.type);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -37,39 +37,38 @@ bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype
|
||||
|
||||
} else n = x->root = mnode_create(nullptr, mnode_empty, 0);
|
||||
|
||||
n->key = vnode_tcreate(x->type, k, kt);
|
||||
n->value = vnode_create(v, vt);
|
||||
n->type = vt;
|
||||
n->key = vnode_tcreate(x->type, key.pointer, key.type);
|
||||
n->value = vnode_create(value.pointer, n->type = value.type);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool libcdsb_map_inject(map_t* x, const void* k, vtype kt, const void* v, vtype vt, void* dt, map_access_callback callback) {
|
||||
bool libcdsb_map_inject(map_t* x, vtype_variable key, vtype_variable value, void* dt, map_access_callback callback) {
|
||||
int cmp;
|
||||
mnode_t* n;
|
||||
mnode_t* p;
|
||||
vnode_t kn;
|
||||
|
||||
vnode_tattach(&kn, x->type, k, kt);
|
||||
n = x->root;
|
||||
kt = x->type;
|
||||
k = vnode_peek(&kn, kt);
|
||||
vnode_tattach(&kn, x->type, key.pointer, key.type);
|
||||
n = x->root;
|
||||
key.type = x->type;
|
||||
key.pointer = vnode_peek(&kn, key.type);
|
||||
|
||||
if (!mnode_is_empty(n)) {
|
||||
do {
|
||||
p = n;
|
||||
cmp = vtype_compare(k, kt, vnode_peek(&n->key, kt), kt);
|
||||
cmp = vtype_compare(key.pointer, key.type, vnode_peek(&n->key, key.type), key.type);
|
||||
|
||||
if (cmp == 0) {
|
||||
if (callback) callback(vnode_peek(&n->key, x->type), x->type,
|
||||
vnode_peek(&n->value, n->type), n->type, dt);
|
||||
if (callback) callback(libcdsb_variable_build(vnode_peek(&n->key, x->type), x->type),
|
||||
libcdsb_variable_build(vnode_peek(&n->value, n->type), n->type), dt);
|
||||
|
||||
vnode_free(&n->key, x->type);
|
||||
vnode_free(&n->value, n->type);
|
||||
|
||||
n->key = kn;
|
||||
vnode_attach(&n->value, v, n->type = vt);
|
||||
vnode_attach(&n->value, value.pointer, n->type = value.type);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -87,7 +86,7 @@ bool libcdsb_map_inject(map_t* x, const void* k, vtype kt, const void* v, vtype
|
||||
|
||||
} else n = x->root = mnode_create(kn, mnode_empty, 0);
|
||||
|
||||
vnode_attach(&n->value, v, n->type = vt);
|
||||
vnode_attach(&n->value, value.pointer, n->type = value.type);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user