Array access standardization
This commit is contained in:
parent
01a62cfaf3
commit
ab75d629d3
@ -12,7 +12,7 @@
|
||||
extern void array_init(vtype_array* x, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
|
||||
extern void* array_at(const vtype_array* s, ssize_t index) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern _Bool array_slice(vtype_array* x, vtype_array* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern _Bool array_slice(vtype_array* x, vtype_array* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
|
||||
|
||||
extern void array_sort (vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern void array_reverse(vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
|
@ -6,20 +6,18 @@
|
||||
#ifndef LIBCDSB_EXTRA_ARRAY_H
|
||||
#define LIBCDSB_EXTRA_ARRAY_H
|
||||
|
||||
typedef int (*array_foreach_callback)(void* value, ssize_t index, vtype type, void* data);
|
||||
typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, void* data);
|
||||
|
||||
|
||||
#define array_get(x, s, index) libcdsb_array_get(x, s, index, 0)
|
||||
#define array_pop(x, s, index) libcdsb_array_get(x, s, index, 1)
|
||||
#define array_remove(s, index) libcdsb_array_get(0, s, index, 1)
|
||||
#define array_get(s, index, data, callback) libcdsb_array_get(s, index, data, callback, 0)
|
||||
#define array_pop(s, index, data, callback) libcdsb_array_get(s, index, data, callback, 1)
|
||||
#define array_remove(s, index) libcdsb_array_get(s, index, 0, 0, 1)
|
||||
|
||||
#define array_foreach(x, data, callback) libcdsb_array_foreach(x, data, callback, 0)
|
||||
|
||||
extern ssize_t libcdsb_array_get(vtype_value* x, vtype_array* s, ssize_t index, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn2__;
|
||||
|
||||
extern int libcdsb_array_get (vtype_array* x, ssize_t index, void* data, array_access_callback, vtype_bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern ssize_t libcdsb_array_find(const vtype_array* x, const void* value, vtype value_type) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
extern ssize_t libcdsb_array_push( vtype_array* x, const void* value, vtype value_type) LIBCDSB_nt__ LIBCDSB_nn1__;
|
||||
|
||||
extern int libcdsb_array_foreach(vtype_array* x, void* data, array_foreach_callback, _Bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
|
||||
extern int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback, vtype_bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
|
||||
|
||||
#endif /* LIBCDSB_EXTRA_ARRAY_H */
|
||||
|
@ -38,6 +38,7 @@ ssize_t libcdsb_array_find(const arr_t* x, const void* v, vtype vt) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ssize_t libcdsb_array_push(arr_t* x, const void* v, vtype vt) {
|
||||
ssize_t i = x->size;
|
||||
vnode_t n = vnode_tcreate(x->type, v, vt);
|
||||
@ -51,32 +52,23 @@ ssize_t libcdsb_array_push(arr_t* x, const void* v, vtype vt) {
|
||||
return i;
|
||||
}
|
||||
|
||||
ssize_t libcdsb_array_get(val_t* x, arr_t* s, ssize_t i, _Bool cut) {
|
||||
|
||||
if (i < 0 && (i += s->size) < 0) i = 0;
|
||||
int libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback callback, vtype_bool cut) {
|
||||
|
||||
if (i < s->size) {
|
||||
assert(!is_null(s->mem));
|
||||
int r = 0;
|
||||
|
||||
if (cut) {
|
||||
if (!is_null(x)) {
|
||||
vnode_t n = vnode_create(array_internal_at(s, i), s->type);
|
||||
value_set(x, n, s->type, VF_WRITEABLE|VF_REMOVABLE);
|
||||
}
|
||||
if (i < 0 && (i += x->size) < 0) i = 0;
|
||||
|
||||
array_cut(s, i, 1);
|
||||
} else value_set(x, array_internal_at(s, i), s->type, VF_WRITEABLE);
|
||||
} else {
|
||||
i = -1;
|
||||
memset(x, 0, sizeof(*x));
|
||||
}
|
||||
if (i < x->size) {
|
||||
if (callback) r = callback(array_internal_at(x, i), i, x->type, _);
|
||||
if (cut) array_cut(x, i, 1);
|
||||
} else return -1;
|
||||
|
||||
return i;
|
||||
return r;
|
||||
}
|
||||
|
||||
/*#####################################################################################################################*/
|
||||
|
||||
int libcdsb_array_foreach(vtype_array* x, void* data, array_foreach_callback callback, _Bool flush) {
|
||||
int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback callback, _Bool flush) {
|
||||
|
||||
void* p;
|
||||
void* e;
|
||||
|
Loading…
Reference in New Issue
Block a user