Update list (vtype_variable)

This commit is contained in:
Gregory Lirent 2023-03-23 13:53:46 +03:00
parent b21ce2e799
commit 6fc4be2b75
3 changed files with 28 additions and 29 deletions

View File

@ -7,7 +7,7 @@
#ifndef LIBCDSB_LIST_H #ifndef LIBCDSB_LIST_H
#define LIBCDSB_LIST_H #define LIBCDSB_LIST_H
typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data); typedef int (*list_access_callback)(vtype_variable, ssize_t index, void* data);
/*#####################################################################################################################*/ /*#####################################################################################################################*/
@ -21,19 +21,19 @@ inline void list_init (vtype_list* x) { x->first = x->last = 0; }
/*#####################################################################################################################*/ /*#####################################################################################################################*/
#define list_pop(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 1) #define list_pop(x, value, data, callback) libcdsb_list_find (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), data, callback, 0, 1)
#define list_get list_find #define list_get list_find
#define list_pop_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 1) #define list_pop_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 1)
#define list_get_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 0) #define list_get_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 0)
#define list_find(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 0) #define list_find(x, value, data, callback) libcdsb_list_find (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), data, callback, 0, 0)
#define list_rfind(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1, 0) #define list_rfind(x, value, data, callback) libcdsb_list_find (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), data, callback, 1, 0)
#define list_countof(x, value) libcdsb_list_count (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) #define list_countof(x, value) libcdsb_list_count (x, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)))
#define list_insert(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) #define list_insert(x, index, value) libcdsb_list_insert (x, index, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), -1, 0, 0)
#define list_replace(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 0, 0, 0) #define list_replace(x, index, value) libcdsb_list_insert (x, index, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), 0, 0, 0)
#define list_push_back(x, value) libcdsb_list_insert (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1, 0, 0) #define list_push_back(x, value) libcdsb_list_insert (x, -1, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), 1, 0, 0)
#define list_push_front(x, value) libcdsb_list_insert (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) #define list_push_front(x, value) libcdsb_list_insert (x, 0, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), -1, 0, 0)
#define list_attach_back(x, value) libcdsb_list_attach (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1, 0, 0) #define list_attach_back(x, value) libcdsb_list_attach (x, -1, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), 1, 0, 0)
#define list_attach_front(x, value) libcdsb_list_attach (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) #define list_attach_front(x, value) libcdsb_list_attach (x, 0, libcdsb_variable_build(_LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)), -1, 0, 0)
#define list_foreach(x, data, callback) libcdsb_list_foreach(x, data, callback, 0) #define list_foreach(x, data, callback) libcdsb_list_foreach(x, data, callback, 0)
#define list_remove(x, value) list_pop (x, value, 0, 0) #define list_remove(x, value) list_pop (x, value, 0, 0)
#define list_remove_by_index(x, index) list_pop_by_index (x, index, 0, 0) #define list_remove_by_index(x, index) list_pop_by_index (x, index, 0, 0)
@ -42,12 +42,12 @@ inline void list_init (vtype_list* x) { x->first = x->last = 0; }
/*#####################################################################################################################*/ /*#####################################################################################################################*/
extern bool libcdsb_list_insert (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction, void* data, list_access_callback) Nonnull__(1); extern bool libcdsb_list_insert (vtype_list* x, ssize_t index, vtype_variable, int ins_direction, void* data, list_access_callback) Nonnull__(1);
extern bool libcdsb_list_attach (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction, void* data, list_access_callback) Nonnull__(1); extern bool libcdsb_list_attach (vtype_list* x, ssize_t index, vtype_variable, int ins_direction, void* data, list_access_callback) Nonnull__(1);
extern int libcdsb_list_find (vtype_list* x, const void* value, vtype type, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); extern int libcdsb_list_find (vtype_list* x, vtype_variable, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1);
extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) Nonnull__(1); extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) Nonnull__(1);
extern int libcdsb_list_foreach (vtype_list* x, void* data, list_access_callback, bool flush) Nonnull__(1,3); extern int libcdsb_list_foreach (vtype_list* x, void* data, list_access_callback, bool flush) Nonnull__(1,3);
extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t libcdsb_list_count(const vtype_list* s, vtype_variable) Pure__ Warn_unused_result__ Nonnull__(1);
#endif /* LIBCDSB_LIST_H */ #endif /* LIBCDSB_LIST_H */

View File

@ -43,7 +43,7 @@ int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback cal
if (n || is_null(c)) return -1; if (n || is_null(c)) return -1;
i = (callback) ? callback(vnode_peek(&c->node, c->type), i, c->type, _) : 0; i = (callback) ? callback(libcdsb_variable_build(vnode_peek(&c->node, c->type), c->type), i, _) : 0;
if (cut) libcdsb_builtin_cut(x, c); if (cut) libcdsb_builtin_cut(x, c);
@ -51,7 +51,7 @@ int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback cal
} }
int libcdsb_list_find(vtype_list* x, const void* v, vtype t, void* _, list_access_callback callback, bool r, bool cut) { int libcdsb_list_find(vtype_list* x, vtype_variable value, void* _, list_access_callback callback, bool r, bool cut) {
ldir_t dir; ldir_t dir;
lnode_t* c; lnode_t* c;
ssize_t i; ssize_t i;
@ -62,10 +62,10 @@ int libcdsb_list_find(vtype_list* x, const void* v, vtype t, void* _, list_acces
i = 0; i = 0;
while (!is_null(c)) { while (!is_null(c)) {
cmp = vtype_compare(vnode_peek(&c->node, c->type), c->type, v, t); cmp = vtype_compare(vnode_peek(&c->node, c->type), c->type, value.pointer, value.type);
if (cmp == 0) { if (cmp == 0) {
i = (callback) ? callback(vnode_peek(&c->node, c->type), (r)?~i:i, c->type, _) : 0; i = (callback) ? callback(libcdsb_variable_build(vnode_peek(&c->node, c->type), c->type), (r)?~i:i, _) : 0;
if (cut) libcdsb_builtin_cut(x, c); if (cut) libcdsb_builtin_cut(x, c);
@ -91,7 +91,7 @@ int libcdsb_list_foreach(vtype_list* x, void* data, list_access_callback callbac
i = 0; i = 0;
while (!is_null(c)) { while (!is_null(c)) {
if ((r = callback(vnode_peek(&c->node, c->type), i, c->type, data)) != 0) if ((r = callback(libcdsb_variable_build(vnode_peek(&c->node, c->type), c->type), i, data)) != 0)
break; break;
n = c->next; n = c->next;

View File

@ -3,7 +3,7 @@
#include "include.h" #include "include.h"
bool libcdsb_list_insert(list_t* x, ssize_t i, const void* v, vtype t, int ins, void* dt, list_access_callback callback) { bool libcdsb_list_insert(list_t* x, ssize_t i, vtype_variable value, int ins, void* dt, list_access_callback callback) {
ldir_t dir; ldir_t dir;
lnode_t* c; lnode_t* c;
@ -42,18 +42,17 @@ bool libcdsb_list_insert(list_t* x, ssize_t i, const void* v, vtype t, int ins,
ldir_dir(ldir_inv(c, dir), dir) = c; ldir_dir(ldir_inv(c, dir), dir) = c;
} else { } else {
if (callback) callback(vnode_peek(&c->node, c->type), -1, c->type, dt); if (callback) callback(libcdsb_variable_build(vnode_peek(&c->node, c->type), c->type), -1, dt);
vnode_free(&c->node, c->type); vnode_free(&c->node, c->type);
} }
c->node = vnode_create(v, t); c->node = vnode_create(value.pointer, c->type = value.type);
c->type = t;
return true; return true;
} }
bool libcdsb_list_attach(list_t* x, ssize_t i, const void* v, vtype t, int ins, void* dt, list_access_callback callback) { bool libcdsb_list_attach(list_t* x, ssize_t i, vtype_variable value, int ins, void* dt, list_access_callback callback) {
ldir_t dir; ldir_t dir;
lnode_t* c; lnode_t* c;
@ -92,11 +91,11 @@ bool libcdsb_list_attach(list_t* x, ssize_t i, const void* v, vtype t, int ins,
ldir_dir(ldir_inv(c, dir), dir) = c; ldir_dir(ldir_inv(c, dir), dir) = c;
} else { } else {
if (callback) callback(vnode_peek(&c->node, c->type), -1, c->type, dt); if (callback) callback(libcdsb_variable_build(vnode_peek(&c->node, c->type), c->type), -1, dt);
vnode_free(&c->node, c->type); vnode_free(&c->node, c->type);
} }
vnode_attach(&c->node, v, c->type = t); vnode_attach(&c->node, value.pointer, c->type = value.type);
return true; return true;
} }