Map access standardization
This commit is contained in:
+31
-31
@@ -3,36 +3,6 @@
|
||||
|
||||
#include "include.h"
|
||||
|
||||
|
||||
_Bool libcdsb_map_find(val_t* x, map_t* s, const void* k, vtype t, _Bool cut) {
|
||||
mnode_t* c;
|
||||
int cmp;
|
||||
|
||||
c = s->root;
|
||||
|
||||
while (!mnode_is_empty(c)) {
|
||||
|
||||
cmp = vtype_compare(vnode_peek(&c->key, s->type), s->type, k, t);
|
||||
|
||||
if (cmp == 0) {
|
||||
if (cut) {
|
||||
c = mnode_delete(&s->root, c);
|
||||
if (!is_null(x)) {
|
||||
value_set(x, c->value, c->type, VF_WRITEABLE|VF_REMOVABLE);
|
||||
} else vnode_free(&c->value, c->type);
|
||||
vnode_free(&c->key, s->type);
|
||||
free(c);
|
||||
} else if (!is_null(x)) value_set(x, &c->value, c->type, VF_WRITEABLE|VF_CHANGEABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
c = (cmp < 0) ? c->right : c->left;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
_Bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype vt) {
|
||||
int cmp;
|
||||
mnode_t* n;
|
||||
@@ -80,7 +50,37 @@ _Bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype
|
||||
}
|
||||
|
||||
|
||||
int libcdsb_map_foreach(map_t* x, void* dt, map_foreach_callback callback, _Bool flush) {
|
||||
int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callback callback, _Bool cut) {
|
||||
mnode_t* c;
|
||||
void *key;
|
||||
int cmp;
|
||||
|
||||
c = x->root;
|
||||
|
||||
while (!mnode_is_empty(c)) {
|
||||
key = vnode_peek(&c->key, x->type);
|
||||
cmp = vtype_compare(key, x->type, k, t);
|
||||
|
||||
if (cmp == 0) {
|
||||
cmp = (callback) ? callback(key, x->type, vnode_peek(&c->value, c->type), c->type, _) : 0;
|
||||
|
||||
if (cut) {
|
||||
c = mnode_delete(&x->root, c);
|
||||
vnode_free(&c->key, x->type);
|
||||
vnode_free(&c->value, c->type);
|
||||
free(c);
|
||||
}
|
||||
|
||||
return cmp;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int libcdsb_map_foreach(map_t* x, void* dt, map_access_callback callback, _Bool flush) {
|
||||
stack_t z = { .prev = 0, .value = x->root };
|
||||
int r = 0;
|
||||
mnode_t* c;
|
||||
|
||||
+19
-19
@@ -3,25 +3,25 @@
|
||||
|
||||
#include "include.h"
|
||||
|
||||
_Bool libcdsb_map_find_pointer(val_t* x, map_t* s, const void* k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_cstring(val_t* x, map_t* s, const char* k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_string (val_t* x, map_t* s, const str_t* k, _Bool cut) { return libcdsb_map_find(x, s, k, vtypeof( k), cut); }
|
||||
_Bool libcdsb_map_find_array (val_t* x, map_t* s, const arr_t* k, _Bool cut) { return libcdsb_map_find(x, s, k, vtypeof( k), cut); }
|
||||
_Bool libcdsb_map_find_list (val_t* x, map_t* s, const list_t* k, _Bool cut) { return libcdsb_map_find(x, s, k, vtypeof( k), cut); }
|
||||
_Bool libcdsb_map_find_map (val_t* x, map_t* s, const map_t* k, _Bool cut) { return libcdsb_map_find(x, s, k, vtypeof( k), cut); }
|
||||
_Bool libcdsb_map_find_vset (val_t* x, map_t* s, const set_t* k, _Bool cut) { return libcdsb_map_find(x, s, k, vtypeof( k), cut); }
|
||||
_Bool libcdsb_map_find_boolean(val_t* x, map_t* s, _Bool k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_int8 (val_t* x, map_t* s, s8_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_int16 (val_t* x, map_t* s, s16_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_int32 (val_t* x, map_t* s, s32_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_int64 (val_t* x, map_t* s, s64_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_uint8 (val_t* x, map_t* s, u8_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_uint16 (val_t* x, map_t* s, u16_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_uint32 (val_t* x, map_t* s, u32_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_uint64 (val_t* x, map_t* s, u64_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_float (val_t* x, map_t* s, fl_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_double (val_t* x, map_t* s, dbl_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
_Bool libcdsb_map_find_ldouble(val_t* x, map_t* s, ldbl_t k, _Bool cut) { return libcdsb_map_find(x, s, &k, vtypeof(&k), cut); }
|
||||
int libcdsb_map_find_pointer(map_t* x, const void* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_cstring(map_t* x, const char* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_string (map_t* x, const str_t* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); }
|
||||
int libcdsb_map_find_array (map_t* x, const arr_t* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); }
|
||||
int libcdsb_map_find_list (map_t* x, const list_t* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); }
|
||||
int libcdsb_map_find_map (map_t* x, const map_t* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); }
|
||||
int libcdsb_map_find_vset (map_t* x, const set_t* k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); }
|
||||
int libcdsb_map_find_boolean(map_t* x, _Bool k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_int8 (map_t* x, s8_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_int16 (map_t* x, s16_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_int32 (map_t* x, s32_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_int64 (map_t* x, s64_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_uint8 (map_t* x, u8_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_uint16 (map_t* x, u16_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_uint32 (map_t* x, u32_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_uint64 (map_t* x, u64_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_float (map_t* x, fl_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_double (map_t* x, dbl_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
int libcdsb_map_find_ldouble(map_t* x, ldbl_t k, void* _, map_access_callback cb, _Bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); }
|
||||
|
||||
_Bool libcdsb_map_update_pointer_pointer(map_t* x, const void* k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); }
|
||||
_Bool libcdsb_map_update_pointer_cstring(map_t* x, const void* k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); }
|
||||
|
||||
Reference in New Issue
Block a user