Add array (extra) foreach

This commit is contained in:
2022-06-05 20:01:10 +03:00
parent 4c9cd1525d
commit 355c822e61
2 changed files with 28 additions and 2 deletions
+24
View File
@@ -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;
}