1.1 --- a/src/linked_list.c Mon Jan 23 20:22:11 2023 +0100 1.2 +++ b/src/linked_list.c Mon Jan 23 20:34:18 2023 +0100 1.3 @@ -38,8 +38,7 @@ 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_f(node, follow_ptr) ((follow_ptr)?CX_LL_PTR(node, loc_data):(((char*)(node))+loc_data)) 1.8 -#define ll_data(node) ll_data_f(node,follow_ptr) 1.9 +#define ll_data(node) (((char*)(node))+loc_data) 1.10 1.11 void *cx_linked_list_at( 1.12 void const *start, 1.13 @@ -62,7 +61,6 @@ 1.14 void const *start, 1.15 ptrdiff_t loc_advance, 1.16 ptrdiff_t loc_data, 1.17 - bool follow_ptr, 1.18 CxListComparator cmp_func, 1.19 void const *elem 1.20 ) { 1.21 @@ -286,7 +284,6 @@ 1.22 ptrdiff_t loc_prev, 1.23 ptrdiff_t loc_next, 1.24 ptrdiff_t loc_data, 1.25 - bool follow_ptr, 1.26 size_t length, 1.27 void *ls, 1.28 void *le, 1.29 @@ -343,7 +340,6 @@ 1.30 ptrdiff_t loc_prev, 1.31 ptrdiff_t loc_next, 1.32 ptrdiff_t loc_data, 1.33 - bool follow_ptr, 1.34 CxListComparator cmp_func 1.35 ) { 1.36 assert(begin != NULL); 1.37 @@ -378,17 +374,17 @@ 1.38 re = ll_next(rc); 1.39 1.40 // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them 1.41 - void *sorted = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, follow_ptr, 1.42 + void *sorted = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, 1.43 ln + rn, ls, le, re, cmp_func); 1.44 1.45 // Something left? Sort it! 1.46 size_t remainder_length = cx_linked_list_size(re, loc_next); 1.47 if (remainder_length > 0) { 1.48 void *remainder = re; 1.49 - cx_linked_list_sort(&remainder, NULL, loc_prev, loc_next, loc_data, follow_ptr, cmp_func); 1.50 + cx_linked_list_sort(&remainder, NULL, loc_prev, loc_next, loc_data, cmp_func); 1.51 1.52 // merge sorted list with (also sorted) remainder 1.53 - *begin = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, follow_ptr, 1.54 + *begin = cx_linked_list_sort_merge(loc_prev, loc_next, loc_data, 1.55 ln + rn + remainder_length, 1.56 sorted, remainder, NULL, cmp_func); 1.57 } else { 1.58 @@ -404,15 +400,13 @@ 1.59 void const *begin_right, 1.60 ptrdiff_t loc_advance, 1.61 ptrdiff_t loc_data, 1.62 - bool follow_ptr_left, 1.63 - bool follow_ptr_right, 1.64 CxListComparator cmp_func 1.65 ) { 1.66 void const *left = begin_left, *right = begin_right; 1.67 1.68 while (left != NULL && right != NULL) { 1.69 - void const *left_data = ll_data_f(left, follow_ptr_left); 1.70 - void const *right_data = ll_data_f(right, follow_ptr_right); 1.71 + void const *left_data = ll_data(left); 1.72 + void const *right_data = ll_data(right); 1.73 int result = cmp_func(left_data, right_data); 1.74 if (result != 0) return result; 1.75 left = ll_advance(left); 1.76 @@ -472,7 +466,6 @@ 1.77 struct cx_list_s base; 1.78 cx_linked_list_node *begin; 1.79 cx_linked_list_node *end; 1.80 - bool follow_ptr; 1.81 } cx_linked_list; 1.82 1.83 static cx_linked_list_node *cx_ll_node_at( 1.84 @@ -576,21 +569,6 @@ 1.85 return cx_ll_insert_array(list, list->size, array, n); 1.86 } 1.87 1.88 -static int cx_pll_insert( 1.89 - struct cx_list_s *list, 1.90 - size_t index, 1.91 - void const *elem 1.92 -) { 1.93 - return cx_ll_insert(list, index, &elem); 1.94 -} 1.95 - 1.96 -static int cx_pll_add( 1.97 - struct cx_list_s *list, 1.98 - void const *elem 1.99 -) { 1.100 - return cx_ll_insert(list, list->size, &elem); 1.101 -} 1.102 - 1.103 static int cx_ll_remove( 1.104 struct cx_list_s *list, 1.105 size_t index 1.106 @@ -623,30 +601,20 @@ 1.107 return node == NULL ? NULL : node->payload; 1.108 } 1.109 1.110 -static void *cx_pll_at( 1.111 - struct cx_list_s const *list, 1.112 - size_t index 1.113 -) { 1.114 - cx_linked_list *ll = (cx_linked_list *) list; 1.115 - cx_linked_list_node *node = cx_ll_node_at(ll, index); 1.116 - return node == NULL ? NULL : *(void **) node->payload; 1.117 -} 1.118 - 1.119 static size_t cx_ll_find( 1.120 struct cx_list_s const *list, 1.121 void const *elem 1.122 ) { 1.123 - cx_linked_list *ll = (cx_linked_list *) list; 1.124 return cx_linked_list_find(((cx_linked_list *) list)->begin, 1.125 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.126 - ll->follow_ptr, list->cmpfunc, elem); 1.127 + list->cmpfunc, elem); 1.128 } 1.129 1.130 static void cx_ll_sort(struct cx_list_s *list) { 1.131 cx_linked_list *ll = (cx_linked_list *) list; 1.132 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 1.133 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.134 - ll->follow_ptr, list->cmpfunc); 1.135 + list->cmpfunc); 1.136 } 1.137 1.138 static void cx_ll_reverse(struct cx_list_s *list) { 1.139 @@ -662,7 +630,7 @@ 1.140 cx_linked_list *right = (cx_linked_list *) other; 1.141 return cx_linked_list_compare(left->begin, right->begin, 1.142 CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 1.143 - left->follow_ptr, right->follow_ptr, list->cmpfunc); 1.144 + list->cmpfunc); 1.145 } 1.146 1.147 static bool cx_ll_iter_valid(void const *it) { 1.148 @@ -696,12 +664,6 @@ 1.149 return node->payload; 1.150 } 1.151 1.152 -static void *cx_pll_iter_current(void const *it) { 1.153 - struct cx_iterator_s const *iter = it; 1.154 - cx_linked_list_node *node = iter->elem_handle; 1.155 - return *(void **) node->payload; 1.156 -} 1.157 - 1.158 static bool cx_ll_iter_flag_rm(void *it) { 1.159 struct cx_iterator_base_s *iter = it; 1.160 if (iter->mutating) { 1.161 @@ -729,15 +691,6 @@ 1.162 return iter; 1.163 } 1.164 1.165 -static CxIterator cx_pll_iterator( 1.166 - struct cx_list_s const *list, 1.167 - size_t index 1.168 -) { 1.169 - CxIterator iter = cx_ll_iterator(list, index); 1.170 - iter.base.current = cx_pll_iter_current; 1.171 - return iter; 1.172 -} 1.173 - 1.174 static CxMutIterator cx_ll_mut_iterator( 1.175 struct cx_list_s *list, 1.176 size_t index 1.177 @@ -751,15 +704,6 @@ 1.178 return iter; 1.179 } 1.180 1.181 -static CxMutIterator cx_pll_mut_iterator( 1.182 - struct cx_list_s *list, 1.183 - size_t index 1.184 -) { 1.185 - CxMutIterator iter = cx_ll_mut_iterator(list, index); 1.186 - iter.base.current = cx_pll_iter_current; 1.187 - return iter; 1.188 -} 1.189 - 1.190 static int cx_ll_insert_iter( 1.191 CxMutIterator *iter, 1.192 void const *elem, 1.193 @@ -780,14 +724,6 @@ 1.194 } 1.195 } 1.196 1.197 -static int cx_pll_insert_iter( 1.198 - CxMutIterator *iter, 1.199 - void const *elem, 1.200 - int prepend 1.201 -) { 1.202 - return cx_ll_insert_iter(iter, &elem, prepend); 1.203 -} 1.204 - 1.205 static void cx_ll_destructor(CxList *list) { 1.206 cx_linked_list *ll = (cx_linked_list *) list; 1.207 1.208 @@ -817,23 +753,6 @@ 1.209 cx_ll_mut_iterator, 1.210 }; 1.211 1.212 -static cx_list_class cx_pointer_linked_list_class = { 1.213 - cx_ll_destructor, 1.214 - cx_pll_add, 1.215 - cx_ll_add_array, 1.216 - cx_pll_insert, 1.217 - cx_ll_insert_array, 1.218 - cx_pll_insert_iter, 1.219 - cx_ll_remove, 1.220 - cx_pll_at, 1.221 - cx_ll_find, 1.222 - cx_ll_sort, 1.223 - cx_ll_compare, 1.224 - cx_ll_reverse, 1.225 - cx_pll_iterator, 1.226 - cx_pll_mut_iterator, 1.227 -}; 1.228 - 1.229 CxList *cxLinkedListCreate( 1.230 CxAllocator const *allocator, 1.231 CxListComparator comparator, 1.232 @@ -842,7 +761,6 @@ 1.233 cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); 1.234 if (list == NULL) return NULL; 1.235 1.236 - list->follow_ptr = false; 1.237 list->base.cl = &cx_linked_list_class; 1.238 list->base.allocator = allocator; 1.239 list->base.cmpfunc = comparator; 1.240 @@ -851,20 +769,3 @@ 1.241 1.242 return (CxList *) list; 1.243 } 1.244 - 1.245 -CxList *cxPointerLinkedListCreate( 1.246 - CxAllocator const *allocator, 1.247 - CxListComparator comparator 1.248 -) { 1.249 - cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); 1.250 - if (list == NULL) return NULL; 1.251 - 1.252 - list->follow_ptr = true; 1.253 - list->base.cl = &cx_pointer_linked_list_class; 1.254 - list->base.allocator = allocator; 1.255 - list->base.cmpfunc = comparator; 1.256 - list->base.itemsize = sizeof(void *); 1.257 - list->base.capacity = SIZE_MAX; 1.258 - 1.259 - return (CxList *) list; 1.260 -}