ucx/list.c

branch
newapi
changeset 253
087cc9216f28
parent 174
0358f1d9c506
equal deleted inserted replaced
252:7d176764756d 253:087cc9216f28
113 ) { 113 ) {
114 void **ptr = list->climpl->at(list, index); 114 void **ptr = list->climpl->at(list, index);
115 return ptr == NULL ? NULL : *ptr; 115 return ptr == NULL ? NULL : *ptr;
116 } 116 }
117 117
118 static ssize_t cx_pl_find( 118 static ssize_t cx_pl_find_remove(
119 struct cx_list_s const *list, 119 struct cx_list_s *list,
120 void const *elem 120 void const *elem,
121 bool remove
121 ) { 122 ) {
122 cx_pl_hack_cmpfunc(list); 123 cx_pl_hack_cmpfunc(list);
123 ssize_t ret = list->climpl->find(list, &elem); 124 ssize_t ret = list->climpl->find_remove(list, &elem, remove);
124 cx_pl_unhack_cmpfunc(list); 125 cx_pl_unhack_cmpfunc(list);
125 return ret; 126 return ret;
126 } 127 }
127 128
128 static void cx_pl_sort(struct cx_list_s *list) { 129 static void cx_pl_sort(struct cx_list_s *list) {
169 cx_pl_insert_iter, 170 cx_pl_insert_iter,
170 cx_pl_remove, 171 cx_pl_remove,
171 cx_pl_clear, 172 cx_pl_clear,
172 cx_pl_swap, 173 cx_pl_swap,
173 cx_pl_at, 174 cx_pl_at,
174 cx_pl_find, 175 cx_pl_find_remove,
175 cx_pl_sort, 176 cx_pl_sort,
176 cx_pl_compare, 177 cx_pl_compare,
177 cx_pl_reverse, 178 cx_pl_reverse,
178 cx_pl_iterator, 179 cx_pl_iterator,
179 }; 180 };
206 __attribute__((__unused__)) size_t index 207 __attribute__((__unused__)) size_t index
207 ) { 208 ) {
208 return NULL; 209 return NULL;
209 } 210 }
210 211
211 static ssize_t cx_emptyl_find( 212 static ssize_t cx_emptyl_find_remove(
212 __attribute__((__unused__)) struct cx_list_s const *list, 213 __attribute__((__unused__)) struct cx_list_s *list,
213 __attribute__((__unused__)) void const *elem 214 __attribute__((__unused__)) void const *elem,
215 __attribute__((__unused__)) bool remove
214 ) { 216 ) {
215 return -1; 217 return -1;
216 } 218 }
217 219
218 static int cx_emptyl_compare( 220 static int cx_emptyl_compare(
246 NULL, 248 NULL,
247 NULL, 249 NULL,
248 cx_emptyl_noop, 250 cx_emptyl_noop,
249 NULL, 251 NULL,
250 cx_emptyl_at, 252 cx_emptyl_at,
251 cx_emptyl_find, 253 cx_emptyl_find_remove,
252 cx_emptyl_noop, 254 cx_emptyl_noop,
253 cx_emptyl_compare, 255 cx_emptyl_compare,
254 cx_emptyl_noop, 256 cx_emptyl_noop,
255 cx_emptyl_iterator, 257 cx_emptyl_iterator,
256 }; 258 };
291 ((list->climpl != NULL ? list->climpl->compare : list->cl->compare) != 293 ((list->climpl != NULL ? list->climpl->compare : list->cl->compare) !=
292 (other->climpl != NULL ? other->climpl->compare : other->cl->compare)) 294 (other->climpl != NULL ? other->climpl->compare : other->cl->compare))
293 ) { 295 ) {
294 // lists are definitely different - cannot use internal compare function 296 // lists are definitely different - cannot use internal compare function
295 if (list->size == other->size) { 297 if (list->size == other->size) {
296 CxIterator left = cxListIterator(list); 298 CxIterator left = list->cl->iterator(list, 0, false);
297 CxIterator right = cxListIterator(other); 299 CxIterator right = other->cl->iterator(other, 0, false);
298 for (size_t i = 0; i < list->size; i++) { 300 for (size_t i = 0; i < list->size; i++) {
299 void *leftValue = cxIteratorCurrent(left); 301 void *leftValue = cxIteratorCurrent(left);
300 void *rightValue = cxIteratorCurrent(right); 302 void *rightValue = cxIteratorCurrent(right);
301 int d = list->cmpfunc(leftValue, rightValue); 303 int d = list->cmpfunc(leftValue, rightValue);
302 if (d != 0) { 304 if (d != 0) {

mercurial