diff --git a/include/extra/array.h b/include/extra/array.h index 8cc7c9a..6ec3825 100644 --- a/include/extra/array.h +++ b/include/extra/array.h @@ -12,7 +12,9 @@ extern ssize_t libcdsb_array_get(vtype_value* x, vtype_array* s, ssize_t index, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn2__; -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 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 array_foreach(vtype_array* x, int (*callback)(void* value, ssize_t index, vtype type)) LIBCDSB_nt__ LIBCDSB_nn12__; #endif /* LIBCDSB_EXTRA_ARRAY_H */ diff --git a/include/extra/list.h b/include/extra/list.h index d62b3eb..68f1168 100644 --- a/include/extra/list.h +++ b/include/extra/list.h @@ -11,13 +11,13 @@ #define list_pop_by_index(x, s, index) libcdsb_list_get(x, s, index, 1) #define list_remove_by_index(s, index) libcdsb_list_get(0, s, index, 1) -extern ssize_t libcdsb_list_find (vtype_value* x, vtype_list* s, const void* value, vtype type, _Bool reverse, _Bool cut); -extern _Bool libcdsb_list_update(vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction); +extern ssize_t libcdsb_list_find (vtype_value* x, vtype_list* s, const void* value, vtype type, _Bool reverse, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn2__; +extern _Bool libcdsb_list_update(vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction) LIBCDSB_nt__ LIBCDSB_nn1__; -extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type); +extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__; -extern ssize_t libcdsb_list_get(vtype_value* x, vtype_list* s, ssize_t index, _Bool cut); +extern ssize_t libcdsb_list_get(vtype_value* x, vtype_list* s, ssize_t index, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn2__; -extern int list_foreach(const vtype_list* x, int (*callback)(void* value, ssize_t index, vtype type)); +extern int list_foreach(const vtype_list* x, int (*callback)(void* value, ssize_t index, vtype type)) LIBCDSB_nt__ LIBCDSB_nn12__; #endif /* LIBCDSB_EXTRA_LIST_H */ diff --git a/include/list.h b/include/list.h index 7e1aece..eda1488 100644 --- a/include/list.h +++ b/include/list.h @@ -18,7 +18,7 @@ extern void list_reverse(vtype_list* x); #define list_pop(x, s, value) _LIBCDSB_Generic(libcdsb_list, find, value)(x, s, value, 0, 1) #define list_find(x, s, value) _LIBCDSB_Generic(libcdsb_list, find, value)(x, s, value, 0, 0) #define list_rfind(x, s, value) _LIBCDSB_Generic(libcdsb_list, find, value)(x, s, value, 1, 0) -#define list_countof(s, value) _LIBCDSB_Generic(libcdsb_list, count, value)(x, value) +#define list_countof(s, value) _LIBCDSB_Generic(libcdsb_list, count, value)(s, value) #define list_indexof(s, value) list_find(0, s, value) #define list_remove(s, value) list_pop(0, s, value) #define in_list(s, value) (list_indexof(s, value) >= 0) diff --git a/src/array/extra.c b/src/array/extra.c index 3baefbb..25b1d2c 100644 --- a/src/array/extra.c +++ b/src/array/extra.c @@ -73,3 +73,27 @@ ssize_t libcdsb_array_get(val_t* x, arr_t* s, ssize_t i, _Bool cut) { return i; } + +/*#####################################################################################################################*/ + +int array_foreach(vtype_array* x, int (*callback)(void* value, ssize_t index, vtype type)) { + + void* p; + void* e; + size_t n; + int r; + + p = x->mem; + e = x->mem + x->size*vtype_size(x->type); + n = 0; + + while (p < e) { + if ((r = callback(p, n, x->type))) + return r; + + p += vtype_size(x->type); + ++n; + } + + return 0; +}