Add array (extra) foreach
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user