src/iterator.c

changeset 1070
0a5a356a4486
parent 890
54565fd74e74
--- a/src/iterator.c	Wed Jan 01 13:31:38 2025 +0100
+++ b/src/iterator.c	Wed Jan 01 14:03:49 2025 +0100
@@ -40,6 +40,11 @@
     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) {
@@ -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;
+}

mercurial