ucx/iterator.c

changeset 852
83fdf679df99
parent 816
839fefbdedc7
equal deleted inserted replaced
850:bbe2925eb590 852:83fdf679df99
28 28
29 #include "cx/iterator.h" 29 #include "cx/iterator.h"
30 30
31 #include <string.h> 31 #include <string.h>
32 32
33 static bool cx_iter_valid(void const *it) { 33 static bool cx_iter_valid(const void *it) {
34 struct cx_iterator_s const *iter = it; 34 const struct cx_iterator_s *iter = it;
35 return iter->index < iter->elem_count; 35 return iter->index < iter->elem_count;
36 } 36 }
37 37
38 static void *cx_iter_current(void const *it) { 38 static void *cx_iter_current(const void *it) {
39 struct cx_iterator_s const *iter = it; 39 const struct cx_iterator_s *iter = it;
40 return iter->elem_handle; 40 return iter->elem_handle;
41 }
42
43 static void *cx_iter_current_ptr(const void *it) {
44 const struct cx_iterator_s *iter = it;
45 return *(void**)iter->elem_handle;
41 } 46 }
42 47
43 static void cx_iter_next_fast(void *it) { 48 static void cx_iter_next_fast(void *it) {
44 struct cx_iterator_s *iter = it; 49 struct cx_iterator_s *iter = it;
45 if (iter->base.remove) { 50 if (iter->base.remove) {
100 105
101 return iter; 106 return iter;
102 } 107 }
103 108
104 CxIterator cxIterator( 109 CxIterator cxIterator(
105 void const *array, 110 const void *array,
106 size_t elem_size, 111 size_t elem_size,
107 size_t elem_count 112 size_t elem_count
108 ) { 113 ) {
109 CxIterator iter = cxMutIterator((void*)array, elem_size, elem_count, false); 114 CxIterator iter = cxMutIterator((void*)array, elem_size, elem_count, false);
110 iter.base.mutating = false; 115 iter.base.mutating = false;
111 return iter; 116 return iter;
112 } 117 }
118
119 CxIterator cxMutIteratorPtr(
120 void *array,
121 size_t elem_count,
122 bool remove_keeps_order
123 ) {
124 CxIterator iter = cxMutIterator(array, sizeof(void*), elem_count, remove_keeps_order);
125 iter.base.current = cx_iter_current_ptr;
126 return iter;
127 }
128
129 CxIterator cxIteratorPtr(
130 const void *array,
131 size_t elem_count
132 ) {
133 CxIterator iter = cxMutIteratorPtr((void*) array, elem_count, false);
134 iter.base.mutating = false;
135 return iter;
136 }

mercurial