1.1 --- a/src/linked_list.c Sat May 21 11:22:47 2022 +0200 1.2 +++ b/src/linked_list.c Sat May 21 12:10:25 2022 +0200 1.3 @@ -38,7 +38,8 @@ 1.4 #define ll_prev(node) CX_LL_PTR(node, loc_prev) 1.5 #define ll_next(node) CX_LL_PTR(node, loc_next) 1.6 #define ll_advance(node) CX_LL_PTR(node, loc_advance) 1.7 -#define ll_data(node) (follow_ptr?CX_LL_PTR(node, loc_data):(((char*)node)+loc_data)) 1.8 +#define ll_data_f(node, follow_ptr) ((follow_ptr)?CX_LL_PTR(node, loc_data):(((char*)node)+loc_data)) 1.9 +#define ll_data(node) ll_data_f(node,follow_ptr) 1.10 1.11 void *cx_linked_list_at( 1.12 void const *start, 1.13 @@ -403,13 +404,16 @@ 1.14 void const *begin_right, 1.15 ptrdiff_t loc_advance, 1.16 ptrdiff_t loc_data, 1.17 - bool follow_ptr, 1.18 + bool follow_ptr_left, 1.19 + bool follow_ptr_right, 1.20 CxListComparator cmp_func 1.21 ) { 1.22 void const *left = begin_left, *right = begin_right; 1.23 1.24 while (left != NULL && right != NULL) { 1.25 - int result = cmp_func(ll_data(left), ll_data(right)); 1.26 + void const *left_data = ll_data_f(left, follow_ptr_left); 1.27 + void const *right_data = ll_data_f(right, follow_ptr_right); 1.28 + int result = cmp_func(left_data, right_data); 1.29 if (result != 0) return result; 1.30 left = ll_advance(left); 1.31 right = ll_advance(right); 1.32 @@ -468,6 +472,7 @@ 1.33 struct cx_list_s base; 1.34 cx_linked_list_node *begin; 1.35 cx_linked_list_node *end; 1.36 + bool follow_ptr; 1.37 } cx_linked_list; 1.38 1.39 static cx_linked_list_node *cx_ll_node_at( 1.40 @@ -595,32 +600,17 @@ 1.41 struct cx_list_s const *list, 1.42 void const *elem 1.43 ) { 1.44 + cx_linked_list *ll = (cx_linked_list *) list; 1.45 return cx_linked_list_find(((cx_linked_list *) list)->begin, 1.46 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.47 - false, list->cmpfunc, elem); 1.48 -} 1.49 - 1.50 -static size_t cx_pll_find( 1.51 - struct cx_list_s const *list, 1.52 - void const *elem 1.53 -) { 1.54 - return cx_linked_list_find(((cx_linked_list *) list)->begin, 1.55 - CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.56 - true, list->cmpfunc, elem); 1.57 + ll->follow_ptr, list->cmpfunc, elem); 1.58 } 1.59 1.60 static void cx_ll_sort(struct cx_list_s *list) { 1.61 cx_linked_list *ll = (cx_linked_list *) list; 1.62 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 1.63 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.64 - false, list->cmpfunc); 1.65 -} 1.66 - 1.67 -static void cx_pll_sort(struct cx_list_s *list) { 1.68 - cx_linked_list *ll = (cx_linked_list *) list; 1.69 - cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 1.70 - CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.71 - true, list->cmpfunc); 1.72 + ll->follow_ptr, list->cmpfunc); 1.73 } 1.74 1.75 static void cx_ll_reverse(struct cx_list_s *list) { 1.76 @@ -636,18 +626,7 @@ 1.77 cx_linked_list *right = (cx_linked_list *) other; 1.78 return cx_linked_list_compare(left->begin, right->begin, 1.79 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.80 - false, list->cmpfunc); 1.81 -} 1.82 - 1.83 -static int cx_pll_compare( 1.84 - struct cx_list_s const *list, 1.85 - struct cx_list_s const *other 1.86 -) { 1.87 - cx_linked_list *left = (cx_linked_list *) list; 1.88 - cx_linked_list *right = (cx_linked_list *) other; 1.89 - return cx_linked_list_compare(left->begin, right->begin, 1.90 - CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.91 - true, list->cmpfunc); 1.92 + left->follow_ptr, right->follow_ptr, list->cmpfunc); 1.93 } 1.94 1.95 static bool cx_ll_iter_valid(CxIterator const *iter) { 1.96 @@ -766,9 +745,9 @@ 1.97 cx_pll_insert_iter, 1.98 cx_ll_remove, 1.99 cx_pll_at, 1.100 - cx_pll_find, 1.101 - cx_pll_sort, 1.102 - cx_pll_compare, 1.103 + cx_ll_find, 1.104 + cx_ll_sort, 1.105 + cx_ll_compare, 1.106 cx_ll_reverse, 1.107 cx_pll_iterator, 1.108 }; 1.109 @@ -781,6 +760,7 @@ 1.110 cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); 1.111 if (list == NULL) return NULL; 1.112 1.113 + list->follow_ptr = false; 1.114 list->base.cl = &cx_linked_list_class; 1.115 list->base.allocator = allocator; 1.116 list->base.cmpfunc = comparator; 1.117 @@ -797,6 +777,7 @@ 1.118 cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); 1.119 if (list == NULL) return NULL; 1.120 1.121 + list->follow_ptr = true; 1.122 list->base.cl = &cx_pointer_linked_list_class; 1.123 list->base.allocator = allocator; 1.124 list->base.cmpfunc = comparator;