src/array_list.c

changeset 764
ccbdbd088455
parent 763
741a2040fa33
child 804
5136f2fc32ec
equal deleted inserted replaced
763:741a2040fa33 764:ccbdbd088455
361 } else { 361 } else {
362 return NULL; 362 return NULL;
363 } 363 }
364 } 364 }
365 365
366 static ssize_t cx_arl_find( 366 static ssize_t cx_arl_find_remove(
367 struct cx_list_s const *list, 367 struct cx_list_s *list,
368 void const *elem 368 void const *elem,
369 bool remove
369 ) { 370 ) {
370 assert(list->cmpfunc != NULL); 371 assert(list->cmpfunc != NULL);
371 assert(list->size < SIZE_MAX / 2); 372 assert(list->size < SIZE_MAX / 2);
372 char *cur = ((cx_array_list const *) list)->data; 373 char *cur = ((cx_array_list const *) list)->data;
373 374
374 for (ssize_t i = 0; i < (ssize_t) list->size; i++) { 375 for (ssize_t i = 0; i < (ssize_t) list->size; i++) {
375 if (0 == list->cmpfunc(elem, cur)) { 376 if (0 == list->cmpfunc(elem, cur)) {
376 return i; 377 if (remove) {
378 if (0 == cx_arl_remove(list, i)) {
379 return i;
380 } else {
381 return -1;
382 }
383 } else {
384 return i;
385 }
377 } 386 }
378 cur += list->item_size; 387 cur += list->item_size;
379 } 388 }
380 389
381 return -1; 390 return -1;
499 cx_arl_insert_iter, 508 cx_arl_insert_iter,
500 cx_arl_remove, 509 cx_arl_remove,
501 cx_arl_clear, 510 cx_arl_clear,
502 cx_arl_swap, 511 cx_arl_swap,
503 cx_arl_at, 512 cx_arl_at,
504 cx_arl_find, 513 cx_arl_find_remove,
505 cx_arl_sort, 514 cx_arl_sort,
506 cx_arl_compare, 515 cx_arl_compare,
507 cx_arl_reverse, 516 cx_arl_reverse,
508 cx_arl_iterator, 517 cx_arl_iterator,
509 }; 518 };

mercurial