Commit 25e8370c authored by Chris Müller's avatar Chris Müller

lib: add clear and each method to pointer arrays.

parent 01f10ca1
......@@ -331,5 +331,29 @@ cry_ptr_array_get(struct CryPtrArray* array, size_t index)
return 0;
}
void
cry_ptr_array_clear(struct CryPtrArray* array, cry_free_funptr fun)
{
assert(array != 0);
if(fun != 0) {
size_t index = 0;
for(index = 0; index < array->length; ++index)
fun(*(array->data + index));
}
array->length = 0;
}
void
cry_ptr_array_each(struct CryPtrArray* array, cry_foreach_funptr fun, pointer data)
{
assert(array != 0 && fun != 0);
size_t index = 0;
for(index = 0; index < array->length; ++index) {
fun(*(array->data + index), data);
}
}
......@@ -77,6 +77,7 @@ pointer cry_ptr_array_replace(struct CryPtrArray* array, size_t index, pointer
pointer cry_ptr_array_get(struct CryPtrArray* array, size_t index);
void cry_ptr_array_each(struct CryPtrArray* array, cry_foreach_funptr fun, pointer data);
#endif // CRYSTAL_STRUCTURES_ARRAY_H
......@@ -26,6 +26,7 @@
#define CRY_ENTRY_FULL -3
typedef int (*cry_ordering_funptr)(const_pointer a, const_pointer b);
typedef void (*cry_foreach_funptr)(pointer element, pointer data);
typedef void (*cry_free_funptr)(pointer data);
int cry_int_compare(const_pointer a, const_pointer b);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment