Update set (vtype_variable)

This commit is contained in:
Gregory Lirent 2023-03-23 16:21:52 +03:00
parent 7657e72c4f
commit a3107ef73b
3 changed files with 24 additions and 24 deletions

View File

@ -8,7 +8,7 @@
#ifndef LIBCDSB_SET_H
#define LIBCDSB_SET_H
typedef int (*vset_access_callback)(const void* value, vtype type, void* data);
typedef int (*vset_access_callback)(vtype_variable value, void* data);
/*#####################################################################################################################*/
@ -16,10 +16,10 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1);
/*#####################################################################################################################*/
#define vset_pop(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1)
#define vset_get(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0)
#define vset_push(x, value) libcdsb_vset_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value))
#define vset_attach(x, value) libcdsb_vset_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value))
#define vset_pop(x, value, data, callback) libcdsb_vset_find (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), data, callback, 1)
#define vset_get(x, value, data, callback) libcdsb_vset_find (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), data, callback, 0)
#define vset_push(x, value) libcdsb_vset_insert (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)))
#define vset_attach(x, value) libcdsb_vset_attach (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)))
#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, RBFOREACH_UNSPECIFIED, 0)
#define vset_remove(x, value) vset_pop (x, value, 0, 0)
@ -27,9 +27,9 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1);
/*#####################################################################################################################*/
extern bool libcdsb_vset_insert (vtype_set* x, const void* value, vtype type) Nonnull__(1);
extern bool libcdsb_vset_attach (vtype_set* x, const void* value, vtype type) Nonnull__(1);
extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, rbforeach_t, bool flush) Nonnull__(1,3);
extern bool libcdsb_vset_insert (vtype_set* x, vtype_variable) Nonnull__(1);
extern bool libcdsb_vset_attach (vtype_set* x, vtype_variable) Nonnull__(1);
extern int libcdsb_vset_find (vtype_set* x, vtype_variable, void* data, vset_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, rbforeach_t, bool flush) Nonnull__(1,3);
#endif /* LIBCDSB_SET_H */

View File

@ -23,7 +23,7 @@ static int libcdsb_builtin_foreach(set_t* x, void* data, vset_access_callback ca
if (!rbnode_is_empty(n->right)) cur = stack_insert(cur, n->right);
if (!r) {
r = callback(vnode_peek(&n->value, x->type), x->type, data);
r = callback(libcdsb_variable_build(vnode_peek(&n->value, x->type), x->type), data);
} else {
stack_flush(&z);
return r;
@ -46,7 +46,7 @@ static int libcdsb_builtin_foreach(set_t* x, void* data, vset_access_callback ca
/*#####################################################################################################################*/
int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access_callback callback, bool cut) {
int libcdsb_vset_find(vtype_set* x, vtype_variable value, void* _, vset_access_callback callback, bool cut) {
rbnode_t* c;
void *val;
int cmp;
@ -55,10 +55,10 @@ int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access
while (!rbnode_is_empty(c)) {
val = vnode_peek(&c->value, x->type);
cmp = vtype_compare(v, t, val, x->type);
cmp = vtype_compare(value.pointer, value.type, val, x->type);
if (cmp == 0) {
cmp = (callback) ? callback(val, x->type, _) : 0;
cmp = (callback) ? callback(libcdsb_variable_build(val, x->type), _) : 0;
if (cut) {
c = rbnode_delete(&x->root, c);
@ -96,7 +96,7 @@ int libcdsb_vset_foreach(set_t* x, void* data, vset_access_callback callback, rb
while ((n = stack_pop(&iter))) {
if (!r) {
r = callback(vnode_peek(&n->value, x->type), x->type, data);
r = callback(libcdsb_variable_build(vnode_peek(&n->value, x->type), x->type), data);
} else if (!flush) {
stack_flush(&iter);
return r;

View File

@ -5,7 +5,7 @@
#include "../__internal/rbtree.h"
#include "../__internal/assert.h"
bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
bool libcdsb_vset_insert(set_t* x, vtype_variable value) {
int cmp;
rbnode_t* n;
rbnode_t* p;
@ -13,7 +13,7 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
if (!rbnode_is_empty(n = x->root)) {
do {
p = n;
cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t);
cmp = vtype_compare(value.pointer, value.type, vnode_peek(&n->value, value.type), value.type);
if (cmp == 0) return false;
@ -30,30 +30,30 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
} else n = x->root = rbnode_create(nullptr, rbnode_empty, 0);
n->value = vnode_tcreate(x->type, v, t);
n->value = vnode_tcreate(x->type, value.pointer, value.type);
return true;
}
bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) {
bool libcdsb_vset_attach(set_t* x, vtype_variable value) {
int cmp;
rbnode_t* n;
rbnode_t* p;
vnode_t vn;
vnode_tattach(&vn, x->type, v, t);
n = x->root;
t = x->type;
v = vnode_peek(&vn, t);
vnode_tattach(&vn, x->type, value.pointer, value.type);
n = x->root;
value.type = x->type;
value.pointer = vnode_peek(&vn, value.type);
if (!rbnode_is_empty(n)) {
do {
p = n;
cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t);
cmp = vtype_compare(value.pointer, value.type, vnode_peek(&n->value, value.type), value.type);
if (cmp == 0) {
vnode_free(&vn, t);
vnode_free(&vn, value.type);
return false;
}