src/linked_list.c

changeset 655
7340c4255f1f
parent 654
c9d008861178
child 661
0a71ac9547fd
equal deleted inserted replaced
654:c9d008861178 655:7340c4255f1f
762 cx_linked_list_node *node = iter->elem_handle; 762 cx_linked_list_node *node = iter->elem_handle;
763 iter->elem_handle = node->next; 763 iter->elem_handle = node->next;
764 } 764 }
765 } 765 }
766 766
767 static void cx_ll_iter_prev(void *it) {
768 struct cx_iterator_base_s *itbase = it;
769 if (itbase->remove) {
770 itbase->remove = false;
771 struct cx_mut_iterator_s *iter = it;
772 cx_linked_list *ll = iter->src_handle;
773 cx_linked_list_node *node = iter->elem_handle;
774 iter->elem_handle = node->prev;
775 iter->index--;
776 cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end,
777 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node);
778 ll->base.size--;
779 cxFree(ll->base.allocator, node);
780 } else {
781 struct cx_iterator_s *iter = it;
782 iter->index--;
783 cx_linked_list_node *node = iter->elem_handle;
784 iter->elem_handle = node->prev;
785 }
786 }
787
767 static void *cx_ll_iter_current(void const *it) { 788 static void *cx_ll_iter_current(void const *it) {
768 struct cx_iterator_s const *iter = it; 789 struct cx_iterator_s const *iter = it;
769 cx_linked_list_node *node = iter->elem_handle; 790 cx_linked_list_node *node = iter->elem_handle;
770 return node->payload; 791 return node->payload;
771 } 792 }
780 } 801 }
781 } 802 }
782 803
783 static CxIterator cx_ll_iterator( 804 static CxIterator cx_ll_iterator(
784 struct cx_list_s const *list, 805 struct cx_list_s const *list,
785 size_t index 806 size_t index,
807 bool backwards
786 ) { 808 ) {
787 CxIterator iter; 809 CxIterator iter;
788 iter.index = index; 810 iter.index = index;
789 iter.src_handle = list; 811 iter.src_handle = list;
790 iter.elem_handle = cx_ll_node_at((cx_linked_list const *) list, index); 812 iter.elem_handle = cx_ll_node_at((cx_linked_list const *) list, index);
791 iter.base.valid = cx_ll_iter_valid; 813 iter.base.valid = cx_ll_iter_valid;
792 iter.base.current = cx_ll_iter_current; 814 iter.base.current = cx_ll_iter_current;
793 iter.base.next = cx_ll_iter_next; 815 iter.base.next = backwards ? cx_ll_iter_prev : cx_ll_iter_next;
794 iter.base.flag_removal = cx_ll_iter_flag_rm; 816 iter.base.flag_removal = cx_ll_iter_flag_rm;
795 iter.base.mutating = false; 817 iter.base.mutating = false;
796 iter.base.remove = false; 818 iter.base.remove = false;
797 return iter; 819 return iter;
798 } 820 }

mercurial