Set access standardization
This commit is contained in:
parent
426f391561
commit
4b3204c00f
@ -6,14 +6,11 @@
|
||||
#ifndef LIBCDSB_EXTRA_SET_H
|
||||
#define LIBCDSB_EXTRA_SET_H
|
||||
|
||||
typedef int (*vset_foreach_callback)(const void* value, vtype type, void* data);
|
||||
|
||||
|
||||
#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, 0)
|
||||
|
||||
extern _Bool libcdsb_vset_find (vtype_value* x, vtype_set* s, const void* value, vtype type, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn23__;
|
||||
extern _Bool libcdsb_vset_insert(vtype_set* x, const void* value, vtype type) LIBCDSB_nt__ LIBCDSB_nn12__;
|
||||
extern _Bool libcdsb_vset_insert(vtype_set* x, const void* value, vtype type) LIBCDSB_nt__ LIBCDSB_nn12__;
|
||||
|
||||
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_foreach_callback, _Bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
|
||||
extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, _Bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
|
||||
|
||||
#endif /* LIBCDSB_EXTRA_SET_H */
|
||||
|
@ -7,6 +7,8 @@
|
||||
#ifndef LIBCDSB_SET_H
|
||||
#define LIBCDSB_SET_H
|
||||
|
||||
typedef int (*vset_access_callback)(const void* value, vtype type, void* data);
|
||||
|
||||
extern void vset_init(vtype_set* x, vtype type);
|
||||
|
||||
#define vset_remove(x, value) _LIBCDSB_Generic (libcdsb_vset, touch, value)(x, value, 1)
|
||||
@ -34,24 +36,24 @@ extern _Bool libcdsb_vset_push_float (vtype_set* x, vtype_float value)
|
||||
extern _Bool libcdsb_vset_push_double (vtype_set* x, vtype_double value);
|
||||
extern _Bool libcdsb_vset_push_ldouble(vtype_set* x, vtype_ldouble value);
|
||||
|
||||
extern _Bool libcdsb_vset_touch_pointer(vtype_set* x, const void* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_cstring(vtype_set* x, const char* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_string (vtype_set* x, const vtype_string* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_array (vtype_set* x, const vtype_array* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_list (vtype_set* x, const vtype_list* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_map (vtype_set* x, const vtype_map* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_vset (vtype_set* x, const vtype_set* value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_boolean(vtype_set* x, vtype_bool value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_uint8 (vtype_set* x, vtype_uint8 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_uint16 (vtype_set* x, vtype_uint16 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_uint32 (vtype_set* x, vtype_uint32 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_uint64 (vtype_set* x, vtype_uint64 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_int8 (vtype_set* x, vtype_int8 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_int16 (vtype_set* x, vtype_int16 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_int32 (vtype_set* x, vtype_int32 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_int64 (vtype_set* x, vtype_int64 value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_float (vtype_set* x, vtype_float value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_double (vtype_set* x, vtype_double value, _Bool cut);
|
||||
extern _Bool libcdsb_vset_touch_ldouble(vtype_set* x, vtype_ldouble value, _Bool cut);
|
||||
extern int libcdsb_vset_find_pointer(vtype_set* x, const void* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_cstring(vtype_set* x, const char* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_string (vtype_set* x, const vtype_string* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_array (vtype_set* x, const vtype_array* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_list (vtype_set* x, const vtype_list* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_map (vtype_set* x, const vtype_map* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_vset (vtype_set* x, const vtype_set* value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_boolean(vtype_set* x, vtype_bool value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_uint8 (vtype_set* x, vtype_uint8 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_uint16 (vtype_set* x, vtype_uint16 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_uint32 (vtype_set* x, vtype_uint32 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_uint64 (vtype_set* x, vtype_uint64 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_int8 (vtype_set* x, vtype_int8 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_int16 (vtype_set* x, vtype_int16 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_int32 (vtype_set* x, vtype_int32 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_int64 (vtype_set* x, vtype_int64 value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_float (vtype_set* x, vtype_float value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_double (vtype_set* x, vtype_double value, void* data, vset_access_callback, _Bool cut);
|
||||
extern int libcdsb_vset_find_ldouble(vtype_set* x, vtype_ldouble value, void* data, vset_access_callback, _Bool cut);
|
||||
|
||||
#endif /* LIBCDSB_SET_H */
|
||||
|
@ -4,34 +4,6 @@
|
||||
#include "../../include/extra/set.h"
|
||||
#include "../__internal/rbtree.h"
|
||||
|
||||
_Bool libcdsb_vset_find(val_t* x, set_t* s, const void* v, vtype t, _Bool cut) {
|
||||
rbnode_t* c;
|
||||
int cmp;
|
||||
|
||||
c = s->root;
|
||||
|
||||
while (!rbnode_is_empty(c)) {
|
||||
|
||||
cmp = vtype_compare(vnode_peek(&c->value, s->type), s->type, v, t);
|
||||
|
||||
if (cmp == 0) {
|
||||
if (cut) {
|
||||
c = rbnode_delete(&s->root, c);
|
||||
if (!is_null(x)) {
|
||||
value_set(x, c->value, s->type, VF_WRITEABLE|VF_REMOVABLE);
|
||||
} else vnode_free(&c->value, s->type);
|
||||
free(c);
|
||||
} else if (!is_null(x)) value_set(x, c->value, s->type, VF_UNDEFINED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
c = (cmp < 0) ? c->right : c->left;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
_Bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
|
||||
int cmp;
|
||||
rbnode_t* n;
|
||||
@ -70,7 +42,35 @@ _Bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
|
||||
}
|
||||
|
||||
|
||||
int libcdsb_vset_foreach(set_t* x, void* data, vset_foreach_callback callback, _Bool flush) {
|
||||
int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access_callback callback, _Bool cut) {
|
||||
rbnode_t* c;
|
||||
void *val;
|
||||
int cmp;
|
||||
|
||||
c = x->root;
|
||||
|
||||
while (!rbnode_is_empty(c)) {
|
||||
val = vnode_peek(&c->value, x->type);
|
||||
cmp = vtype_compare(val, x->type, v, t);
|
||||
|
||||
if (cmp == 0) {
|
||||
cmp = (callback) ? callback(val, x->type, _) : 0;
|
||||
|
||||
if (cut) {
|
||||
c = rbnode_delete(&x->root, c);
|
||||
vnode_free(&c->value, x->type);
|
||||
free(c);
|
||||
}
|
||||
|
||||
return cmp;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int libcdsb_vset_foreach(set_t* x, void* data, vset_access_callback callback, _Bool flush) {
|
||||
stack_t z = { .prev = 0, .value = x->root };
|
||||
int r = 0;
|
||||
rbnode_t* c;
|
||||
|
@ -4,25 +4,25 @@
|
||||
#include "../../include/extra/set.h"
|
||||
#include "../__internal/include.h"
|
||||
|
||||
_Bool libcdsb_vset_touch_pointer(set_t* x, const void* k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_cstring(set_t* x, const char* k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_string (set_t* x, const str_t* k, _Bool f) { return libcdsb_vset_find(0, x, k, vtypeof( k), f); }
|
||||
_Bool libcdsb_vset_touch_array (set_t* x, const arr_t* k, _Bool f) { return libcdsb_vset_find(0, x, k, vtypeof( k), f); }
|
||||
_Bool libcdsb_vset_touch_list (set_t* x, const list_t* k, _Bool f) { return libcdsb_vset_find(0, x, k, vtypeof( k), f); }
|
||||
_Bool libcdsb_vset_touch_map (set_t* x, const map_t* k, _Bool f) { return libcdsb_vset_find(0, x, k, vtypeof( k), f); }
|
||||
_Bool libcdsb_vset_touch_vset (set_t* x, const set_t* k, _Bool f) { return libcdsb_vset_find(0, x, k, vtypeof( k), f); }
|
||||
_Bool libcdsb_vset_touch_boolean(set_t* x, _Bool k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_int8 (set_t* x, s8_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_int16 (set_t* x, s16_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_int32 (set_t* x, s32_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_int64 (set_t* x, s64_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_uint8 (set_t* x, u8_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_uint16 (set_t* x, u16_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_uint32 (set_t* x, u32_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_uint64 (set_t* x, u64_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_float (set_t* x, fl_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_double (set_t* x, dbl_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
_Bool libcdsb_vset_touch_ldouble(set_t* x, ldbl_t k, _Bool f) { return libcdsb_vset_find(0, x, &k, vtypeof(&k), f); }
|
||||
int libcdsb_vset_find_pointer(set_t* x, const void* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_cstring(set_t* x, const char* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_string (set_t* x, const str_t* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); }
|
||||
int libcdsb_vset_find_array (set_t* x, const arr_t* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); }
|
||||
int libcdsb_vset_find_list (set_t* x, const list_t* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); }
|
||||
int libcdsb_vset_find_map (set_t* x, const map_t* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); }
|
||||
int libcdsb_vset_find_vset (set_t* x, const set_t* v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); }
|
||||
int libcdsb_vset_find_boolean(set_t* x, _Bool v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_int8 (set_t* x, s8_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_int16 (set_t* x, s16_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_int32 (set_t* x, s32_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_int64 (set_t* x, s64_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_uint8 (set_t* x, u8_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_uint16 (set_t* x, u16_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_uint32 (set_t* x, u32_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_uint64 (set_t* x, u64_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_float (set_t* x, fl_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_double (set_t* x, dbl_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
int libcdsb_vset_find_ldouble(set_t* x, ldbl_t v, void* _, vset_access_callback cb, _Bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); }
|
||||
|
||||
_Bool libcdsb_vset_push_pointer(set_t* x, const void* v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); }
|
||||
_Bool libcdsb_vset_push_cstring(set_t* x, const char* v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); }
|
||||
|
Loading…
Reference in New Issue
Block a user