src/array_list.c

changeset 699
35b2b99ee523
parent 678
78f943d76f50
child 708
1caed6c9ba68
equal deleted inserted replaced
698:7345ee0a0301 699:35b2b99ee523
343 } else { 343 } else {
344 return NULL; 344 return NULL;
345 } 345 }
346 } 346 }
347 347
348 static size_t cx_arl_find( 348 static ssize_t cx_arl_find(
349 struct cx_list_s const *list, 349 struct cx_list_s const *list,
350 void const *elem 350 void const *elem
351 ) { 351 ) {
352 assert(list->cmpfunc != NULL); 352 assert(list->cmpfunc != NULL);
353 assert(list->size < SIZE_MAX / 2);
353 char *cur = ((cx_array_list const *) list)->data; 354 char *cur = ((cx_array_list const *) list)->data;
354 355
355 for (size_t i = 0; i < list->size; i++) { 356 for (ssize_t i = 0; i < (ssize_t) list->size; i++) {
356 if (0 == list->cmpfunc(elem, cur)) { 357 if (0 == list->cmpfunc(elem, cur)) {
357 return i; 358 return i;
358 } 359 }
359 cur += list->item_size; 360 cur += list->item_size;
360 } 361 }
361 362
362 return list->size; 363 return -1;
363 } 364 }
364 365
365 static void cx_arl_sort(struct cx_list_s *list) { 366 static void cx_arl_sort(struct cx_list_s *list) {
366 assert(list->cmpfunc != NULL); 367 assert(list->cmpfunc != NULL);
367 qsort(((cx_array_list *) list)->data, 368 qsort(((cx_array_list *) list)->data,

mercurial