Thu, 17 Nov 2022 18:46:55 +0100
#219 array list: implement find
src/array_list.c | file | annotate | diff | comparison | revisions | |
test/test_list.cpp | file | annotate | diff | comparison | revisions |
--- a/src/array_list.c Thu Nov 17 18:32:59 2022 +0100 +++ b/src/array_list.c Thu Nov 17 18:46:55 2022 +0100 @@ -232,7 +232,16 @@ struct cx_list_s const *list, void const *elem ) { - return 0; + char *cur = ((cx_array_list const *) list)->data; + + for (size_t i = 0; i < list->size; i++) { + if (0 == list->cmpfunc(elem, cur)) { + return i; + } + cur += list->itemsize; + } + + return list->size; } static void cx_arl_sort(struct cx_list_s *list) {