--- a/ucx/iterator.c Thu Nov 28 17:53:13 2024 +0100 +++ b/ucx/iterator.c Mon Jan 06 21:18:36 2025 +0100 @@ -30,16 +30,21 @@ #include <string.h> -static bool cx_iter_valid(void const *it) { - struct cx_iterator_s const *iter = it; +static bool cx_iter_valid(const void *it) { + const struct cx_iterator_s *iter = it; return iter->index < iter->elem_count; } -static void *cx_iter_current(void const *it) { - struct cx_iterator_s const *iter = it; +static void *cx_iter_current(const void *it) { + const struct cx_iterator_s *iter = it; return iter->elem_handle; } +static void *cx_iter_current_ptr(const void *it) { + const struct cx_iterator_s *iter = it; + return *(void**)iter->elem_handle; +} + static void cx_iter_next_fast(void *it) { struct cx_iterator_s *iter = it; if (iter->base.remove) { @@ -102,7 +107,7 @@ } CxIterator cxIterator( - void const *array, + const void *array, size_t elem_size, size_t elem_count ) { @@ -110,3 +115,22 @@ iter.base.mutating = false; return iter; } + +CxIterator cxMutIteratorPtr( + void *array, + size_t elem_count, + bool remove_keeps_order +) { + CxIterator iter = cxMutIterator(array, sizeof(void*), elem_count, remove_keeps_order); + iter.base.current = cx_iter_current_ptr; + return iter; +} + +CxIterator cxIteratorPtr( + const void *array, + size_t elem_count +) { + CxIterator iter = cxMutIteratorPtr((void*) array, elem_count, false); + iter.base.mutating = false; + return iter; +}