638 return cx_linked_list_compare(left->begin, right->begin, |
638 return cx_linked_list_compare(left->begin, right->begin, |
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) { |
|
644 return iter->data != NULL; |
|
645 } |
|
646 |
|
647 static void cx_ll_iter_next(CxIterator *iter) { |
|
648 iter->index++; |
|
649 cx_linked_list_node *node = iter->data; |
|
650 iter->data = node->next; |
|
651 } |
|
652 |
|
653 static void *cx_ll_iter_current(CxIterator const *iter) { |
|
654 cx_linked_list_node *node = iter->data; |
|
655 return node->payload; |
|
656 } |
|
657 |
|
658 static void *cx_pll_iter_current(CxIterator const *iter) { |
|
659 cx_linked_list_node *node = iter->data; |
|
660 return *(void **) node->payload; |
|
661 } |
|
662 |
|
663 static CxIterator cx_ll_iterator( |
|
664 cx_list_s const *list, |
|
665 size_t index |
|
666 ) { |
|
667 CxIterator iter; |
|
668 iter.index = index; |
|
669 iter.data = cx_ll_node_at((cx_linked_list const *) list, index); |
|
670 iter.valid = cx_ll_iter_valid; |
|
671 iter.current = cx_ll_iter_current; |
|
672 iter.next = cx_ll_iter_next; |
|
673 return iter; |
|
674 } |
|
675 |
|
676 static CxIterator cx_pll_iterator( |
|
677 cx_list_s const *list, |
|
678 size_t index |
|
679 ) { |
|
680 CxIterator iter = cx_ll_iterator(list, index); |
|
681 iter.current = cx_pll_iter_current; |
|
682 return iter; |
|
683 } |
|
684 |
643 static cx_list_class cx_linked_list_class = { |
685 static cx_list_class cx_linked_list_class = { |
644 cx_ll_add, |
686 cx_ll_add, |
645 cx_ll_insert, |
687 cx_ll_insert, |
646 cx_ll_remove, |
688 cx_ll_remove, |
647 cx_ll_at, |
689 cx_ll_at, |
648 cx_ll_find, |
690 cx_ll_find, |
649 cx_ll_sort, |
691 cx_ll_sort, |
650 cx_ll_compare, |
692 cx_ll_compare, |
651 cx_ll_reverse |
693 cx_ll_reverse, |
|
694 cx_ll_iterator, |
652 }; |
695 }; |
653 |
696 |
654 static cx_list_class cx_pointer_linked_list_class = { |
697 static cx_list_class cx_pointer_linked_list_class = { |
655 cx_pll_add, |
698 cx_pll_add, |
656 cx_pll_insert, |
699 cx_pll_insert, |
657 cx_ll_remove, |
700 cx_ll_remove, |
658 cx_pll_at, |
701 cx_pll_at, |
659 cx_pll_find, |
702 cx_pll_find, |
660 cx_pll_sort, |
703 cx_pll_sort, |
661 cx_pll_compare, |
704 cx_pll_compare, |
662 cx_ll_reverse |
705 cx_ll_reverse, |
|
706 cx_pll_iterator, |
663 }; |
707 }; |
664 |
708 |
665 CxList cxLinkedListCreate( |
709 CxList cxLinkedListCreate( |
666 CxAllocator allocator, |
710 CxAllocator allocator, |
667 CxListComparator comparator, |
711 CxListComparator comparator, |