diff -r eafb45eefc51 -r 309e8b08c60e src/linked_list.c --- a/src/linked_list.c Mon Jan 23 20:22:11 2023 +0100 +++ b/src/linked_list.c Mon Jan 23 20:34:18 2023 +0100 @@ -38,8 +38,7 @@ #define ll_prev(node) CX_LL_PTR(node, loc_prev) #define ll_next(node) CX_LL_PTR(node, loc_next) #define ll_advance(node) CX_LL_PTR(node, loc_advance) -#define ll_data_f(node, follow_ptr) ((follow_ptr)?CX_LL_PTR(node, loc_data):(((char*)(node))+loc_data)) -#define ll_data(node) ll_data_f(node,follow_ptr) +#define ll_data(node) (((char*)(node))+loc_data) void *cx_linked_list_at( void const *start, @@ -62,7 +61,6 @@ void const *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, - bool follow_ptr, CxListComparator cmp_func, void const *elem ) { @@ -286,7 +284,6 @@ ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, - bool follow_ptr, size_t length, void *ls, void *le, @@ -343,7 +340,6 @@ ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, - bool follow_ptr, CxListComparator cmp_func ) { assert(begin != NULL); @@ -378,17 +374,17 @@ re = ll_next(rc); // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them - void *sorted = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, follow_ptr, + void *sorted = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, ln + rn, ls, le, re, cmp_func); // Something left? Sort it! size_t remainder_length = cx_linked_list_size(re, loc_next); if (remainder_length > 0) { void *remainder = re; - cx_linked_list_sort(&remainder, NULL, loc_prev, loc_next, loc_data, follow_ptr, cmp_func); + cx_linked_list_sort(&remainder, NULL, loc_prev, loc_next, loc_data, cmp_func); // merge sorted list with (also sorted) remainder - *begin = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, follow_ptr, + *begin = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, ln + rn + remainder_length, sorted, remainder, NULL, cmp_func); } else { @@ -404,15 +400,13 @@ void const *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, - bool follow_ptr_left, - bool follow_ptr_right, CxListComparator cmp_func ) { void const *left = begin_left, *right = begin_right; while (left != NULL && right != NULL) { - void const *left_data = ll_data_f(left, follow_ptr_left); - void const *right_data = ll_data_f(right, follow_ptr_right); + void const *left_data = ll_data(left); + void const *right_data = ll_data(right); int result = cmp_func(left_data, right_data); if (result != 0) return result; left = ll_advance(left); @@ -472,7 +466,6 @@ struct cx_list_s base; cx_linked_list_node *begin; cx_linked_list_node *end; - bool follow_ptr; } cx_linked_list; static cx_linked_list_node *cx_ll_node_at( @@ -576,21 +569,6 @@ return cx_ll_insert_array(list, list->size, array, n); } -static int cx_pll_insert( - struct cx_list_s *list, - size_t index, - void const *elem -) { - return cx_ll_insert(list, index, &elem); -} - -static int cx_pll_add( - struct cx_list_s *list, - void const *elem -) { - return cx_ll_insert(list, list->size, &elem); -} - static int cx_ll_remove( struct cx_list_s *list, size_t index @@ -623,30 +601,20 @@ return node == NULL ? NULL : node->payload; } -static void *cx_pll_at( - struct cx_list_s const *list, - size_t index -) { - cx_linked_list *ll = (cx_linked_list *) list; - cx_linked_list_node *node = cx_ll_node_at(ll, index); - return node == NULL ? NULL : *(void **) node->payload; -} - static size_t cx_ll_find( struct cx_list_s const *list, void const *elem ) { - cx_linked_list *ll = (cx_linked_list *) list; return cx_linked_list_find(((cx_linked_list *) list)->begin, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, - ll->follow_ptr, list->cmpfunc, elem); + list->cmpfunc, elem); } static void cx_ll_sort(struct cx_list_s *list) { cx_linked_list *ll = (cx_linked_list *) list; cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, - ll->follow_ptr, list->cmpfunc); + list->cmpfunc); } static void cx_ll_reverse(struct cx_list_s *list) { @@ -662,7 +630,7 @@ cx_linked_list *right = (cx_linked_list *) other; return cx_linked_list_compare(left->begin, right->begin, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, - left->follow_ptr, right->follow_ptr, list->cmpfunc); + list->cmpfunc); } static bool cx_ll_iter_valid(void const *it) { @@ -696,12 +664,6 @@ return node->payload; } -static void *cx_pll_iter_current(void const *it) { - struct cx_iterator_s const *iter = it; - cx_linked_list_node *node = iter->elem_handle; - return *(void **) node->payload; -} - static bool cx_ll_iter_flag_rm(void *it) { struct cx_iterator_base_s *iter = it; if (iter->mutating) { @@ -729,15 +691,6 @@ return iter; } -static CxIterator cx_pll_iterator( - struct cx_list_s const *list, - size_t index -) { - CxIterator iter = cx_ll_iterator(list, index); - iter.base.current = cx_pll_iter_current; - return iter; -} - static CxMutIterator cx_ll_mut_iterator( struct cx_list_s *list, size_t index @@ -751,15 +704,6 @@ return iter; } -static CxMutIterator cx_pll_mut_iterator( - struct cx_list_s *list, - size_t index -) { - CxMutIterator iter = cx_ll_mut_iterator(list, index); - iter.base.current = cx_pll_iter_current; - return iter; -} - static int cx_ll_insert_iter( CxMutIterator *iter, void const *elem, @@ -780,14 +724,6 @@ } } -static int cx_pll_insert_iter( - CxMutIterator *iter, - void const *elem, - int prepend -) { - return cx_ll_insert_iter(iter, &elem, prepend); -} - static void cx_ll_destructor(CxList *list) { cx_linked_list *ll = (cx_linked_list *) list; @@ -817,23 +753,6 @@ cx_ll_mut_iterator, }; -static cx_list_class cx_pointer_linked_list_class = { - cx_ll_destructor, - cx_pll_add, - cx_ll_add_array, - cx_pll_insert, - cx_ll_insert_array, - cx_pll_insert_iter, - cx_ll_remove, - cx_pll_at, - cx_ll_find, - cx_ll_sort, - cx_ll_compare, - cx_ll_reverse, - cx_pll_iterator, - cx_pll_mut_iterator, -}; - CxList *cxLinkedListCreate( CxAllocator const *allocator, CxListComparator comparator, @@ -842,7 +761,6 @@ cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); if (list == NULL) return NULL; - list->follow_ptr = false; list->base.cl = &cx_linked_list_class; list->base.allocator = allocator; list->base.cmpfunc = comparator; @@ -851,20 +769,3 @@ return (CxList *) list; } - -CxList *cxPointerLinkedListCreate( - CxAllocator const *allocator, - CxListComparator comparator -) { - cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); - if (list == NULL) return NULL; - - list->follow_ptr = true; - list->base.cl = &cx_pointer_linked_list_class; - list->base.allocator = allocator; - list->base.cmpfunc = comparator; - list->base.itemsize = sizeof(void *); - list->base.capacity = SIZE_MAX; - - return (CxList *) list; -}