854 } else { |
854 } else { |
855 return NULL; |
855 return NULL; |
856 } |
856 } |
857 } |
857 } |
858 |
858 |
859 static ssize_t cx_arl_find_remove( |
859 static size_t cx_arl_find_remove( |
860 struct cx_list_s *list, |
860 struct cx_list_s *list, |
861 const void *elem, |
861 const void *elem, |
862 bool remove |
862 bool remove |
863 ) { |
863 ) { |
864 assert(list->collection.cmpfunc != NULL); |
864 assert(list->collection.cmpfunc != NULL); |
865 assert(list->collection.size < SIZE_MAX / 2); |
865 assert(list->collection.size < SIZE_MAX / 2); |
866 char *cur = ((const cx_array_list *) list)->data; |
866 char *cur = ((const cx_array_list *) list)->data; |
867 |
867 |
868 for (ssize_t i = 0; i < (ssize_t) list->collection.size; i++) { |
868 for (size_t i = 0; i < list->collection.size; i++) { |
869 if (0 == list->collection.cmpfunc(elem, cur)) { |
869 if (0 == list->collection.cmpfunc(elem, cur)) { |
870 if (remove) { |
870 if (remove) { |
871 if (1 == cx_arl_remove(list, i, 1, NULL)) { |
871 if (1 == cx_arl_remove(list, i, 1, NULL)) { |
872 return i; |
872 return i; |
873 } else { |
873 } else { |
874 // should be unreachable |
874 // should be unreachable |
875 return -1; // LCOV_EXCL_LINE |
875 return list->collection.size; // LCOV_EXCL_LINE |
876 } |
876 } |
877 } else { |
877 } else { |
878 return i; |
878 return i; |
879 } |
879 } |
880 } |
880 } |
881 cur += list->collection.elem_size; |
881 cur += list->collection.elem_size; |
882 } |
882 } |
883 |
883 |
884 return -1; |
884 return list->collection.size; |
885 } |
885 } |
886 |
886 |
887 static void cx_arl_sort(struct cx_list_s *list) { |
887 static void cx_arl_sort(struct cx_list_s *list) { |
888 assert(list->collection.cmpfunc != NULL); |
888 assert(list->collection.cmpfunc != NULL); |
889 qsort(((cx_array_list *) list)->data, |
889 qsort(((cx_array_list *) list)->data, |