src/list.c

changeset 853
d4baf4dd55c3
parent 802
30473af255b4
child 854
fe0d69d72bcd
equal deleted inserted replaced
852:16e2a3391e88 853:d4baf4dd55c3
78 ) { 78 ) {
79 return list->climpl->insert_array(list, index, array, n); 79 return list->climpl->insert_array(list, index, array, n);
80 } 80 }
81 81
82 static int cx_pl_insert_iter( 82 static int cx_pl_insert_iter(
83 struct cx_mut_iterator_s *iter, 83 struct cx_iterator_s *iter,
84 void const *elem, 84 void const *elem,
85 int prepend 85 int prepend
86 ) { 86 ) {
87 struct cx_list_s *list = iter->src_handle; 87 struct cx_list_s *list = iter->src_handle.m;
88 return list->climpl->insert_iter(iter, &elem, prepend); 88 return list->climpl->insert_iter(iter, &elem, prepend);
89 } 89 }
90 90
91 static int cx_pl_remove( 91 static int cx_pl_remove(
92 struct cx_list_s *list, 92 struct cx_list_s *list,
146 list->climpl->reverse(list); 146 list->climpl->reverse(list);
147 } 147 }
148 148
149 static void *cx_pl_iter_current(void const *it) { 149 static void *cx_pl_iter_current(void const *it) {
150 struct cx_iterator_s const *iter = it; 150 struct cx_iterator_s const *iter = it;
151 void **ptr = iter->base.current_impl(it); 151 void **ptr = iter->current_impl(it);
152 return ptr == NULL ? NULL : *ptr; 152 return ptr == NULL ? NULL : *ptr;
153 } 153 }
154 154
155 static struct cx_iterator_s cx_pl_iterator( 155 static struct cx_iterator_s cx_pl_iterator(
156 struct cx_list_s const *list, 156 struct cx_list_s const *list,
157 size_t index, 157 size_t index,
158 bool backwards 158 bool backwards
159 ) { 159 ) {
160 struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards); 160 struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards);
161 iter.base.current_impl = iter.base.current; 161 iter.current_impl = iter.current;
162 iter.base.current = cx_pl_iter_current; 162 iter.current = cx_pl_iter_current;
163 return iter; 163 return iter;
164 } 164 }
165 165
166 static cx_list_class cx_pointer_list_class = { 166 static cx_list_class cx_pointer_list_class = {
167 cx_pl_destructor, 167 cx_pl_destructor,
233 struct cx_list_s const *list, 233 struct cx_list_s const *list,
234 size_t index, 234 size_t index,
235 __attribute__((__unused__)) bool backwards 235 __attribute__((__unused__)) bool backwards
236 ) { 236 ) {
237 CxIterator iter = {0}; 237 CxIterator iter = {0};
238 iter.src_handle = list; 238 iter.src_handle.c = list;
239 iter.index = index; 239 iter.index = index;
240 iter.base.valid = cx_emptyl_iter_valid; 240 iter.valid = cx_emptyl_iter_valid;
241 return iter; 241 return iter;
242 } 242 }
243 243
244 static cx_list_class cx_empty_list_class = { 244 static cx_list_class cx_empty_list_class = {
245 cx_emptyl_noop, 245 cx_emptyl_noop,
315 // lists are compatible 315 // lists are compatible
316 return list->cl->compare(list, other); 316 return list->cl->compare(list, other);
317 } 317 }
318 } 318 }
319 319
320 CxMutIterator cxListMutIteratorAt( 320 CxIterator cxListMutIteratorAt(
321 CxList *list, 321 CxList *list,
322 size_t index 322 size_t index
323 ) { 323 ) {
324 CxIterator it = list->cl->iterator(list, index, false); 324 CxIterator it = list->cl->iterator(list, index, false);
325 it.base.mutating = true; 325 it.mutating = true;
326 326 return it;
327 // we know the iterators share the same memory layout 327 }
328 CxMutIterator iter; 328
329 memcpy(&iter, &it, sizeof(CxMutIterator)); 329 CxIterator cxListMutBackwardsIteratorAt(
330 return iter;
331 }
332
333 CxMutIterator cxListMutBackwardsIteratorAt(
334 CxList *list, 330 CxList *list,
335 size_t index 331 size_t index
336 ) { 332 ) {
337 CxIterator it = list->cl->iterator(list, index, true); 333 CxIterator it = list->cl->iterator(list, index, true);
338 it.base.mutating = true; 334 it.mutating = true;
339 335 return it;
340 // we know the iterators share the same memory layout 336 }
341 CxMutIterator iter;
342 memcpy(&iter, &it, sizeof(CxMutIterator));
343 return iter;
344 }

mercurial