639 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, |
639 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, |
640 true, list->cmpfunc); |
640 true, list->cmpfunc); |
641 } |
641 } |
642 |
642 |
643 static bool cx_ll_iter_valid(CxIterator const *iter) { |
643 static bool cx_ll_iter_valid(CxIterator const *iter) { |
644 return iter->data != NULL; |
644 return iter->elem_handle != NULL; |
645 } |
645 } |
646 |
646 |
647 static void cx_ll_iter_next(CxIterator *iter) { |
647 static void cx_ll_iter_next(CxIterator *iter) { |
648 iter->index++; |
648 if (iter->remove) { |
649 cx_linked_list_node *node = iter->data; |
649 iter->remove = false; |
650 iter->data = node->next; |
650 cx_linked_list *ll = iter->src_handle; |
|
651 cx_linked_list_node *node = iter->elem_handle; |
|
652 iter->elem_handle = node->next; |
|
653 cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end, |
|
654 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node); |
|
655 ll->base.size--; |
|
656 cxFree(ll->base.allocator, node); |
|
657 } else { |
|
658 iter->index++; |
|
659 cx_linked_list_node *node = iter->elem_handle; |
|
660 iter->elem_handle = node->next; |
|
661 } |
651 } |
662 } |
652 |
663 |
653 static void *cx_ll_iter_current(CxIterator const *iter) { |
664 static void *cx_ll_iter_current(CxIterator const *iter) { |
654 cx_linked_list_node *node = iter->data; |
665 cx_linked_list_node *node = iter->elem_handle; |
655 return node->payload; |
666 return node->payload; |
656 } |
667 } |
657 |
668 |
658 static void *cx_pll_iter_current(CxIterator const *iter) { |
669 static void *cx_pll_iter_current(CxIterator const *iter) { |
659 cx_linked_list_node *node = iter->data; |
670 cx_linked_list_node *node = iter->elem_handle; |
660 return *(void **) node->payload; |
671 return *(void **) node->payload; |
661 } |
672 } |
662 |
673 |
663 static CxIterator cx_ll_iterator( |
674 static CxIterator cx_ll_iterator( |
664 cx_list_s const *list, |
675 cx_list_s *list, |
665 size_t index |
676 size_t index |
666 ) { |
677 ) { |
667 CxIterator iter; |
678 CxIterator iter; |
668 iter.index = index; |
679 iter.index = index; |
669 iter.data = cx_ll_node_at((cx_linked_list const *) list, index); |
680 iter.src_handle = list; |
|
681 iter.elem_handle = cx_ll_node_at((cx_linked_list const *) list, index); |
670 iter.valid = cx_ll_iter_valid; |
682 iter.valid = cx_ll_iter_valid; |
671 iter.current = cx_ll_iter_current; |
683 iter.current = cx_ll_iter_current; |
672 iter.next = cx_ll_iter_next; |
684 iter.next = cx_ll_iter_next; |
|
685 iter.remove = false; |
673 return iter; |
686 return iter; |
674 } |
687 } |
675 |
688 |
676 static CxIterator cx_pll_iterator( |
689 static CxIterator cx_pll_iterator( |
677 cx_list_s const *list, |
690 cx_list_s *list, |
678 size_t index |
691 size_t index |
679 ) { |
692 ) { |
680 CxIterator iter = cx_ll_iterator(list, index); |
693 CxIterator iter = cx_ll_iterator(list, index); |
681 iter.current = cx_pll_iter_current; |
694 iter.current = cx_pll_iter_current; |
682 return iter; |
695 return iter; |