src/array_list.c

changeset 764
ccbdbd088455
parent 763
741a2040fa33
child 804
5136f2fc32ec
     1.1 --- a/src/array_list.c	Mon Dec 18 16:14:07 2023 +0100
     1.2 +++ b/src/array_list.c	Mon Dec 18 18:22:53 2023 +0100
     1.3 @@ -363,9 +363,10 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -static ssize_t cx_arl_find(
     1.8 -        struct cx_list_s const *list,
     1.9 -        void const *elem
    1.10 +static ssize_t cx_arl_find_remove(
    1.11 +        struct cx_list_s *list,
    1.12 +        void const *elem,
    1.13 +        bool remove
    1.14  ) {
    1.15      assert(list->cmpfunc != NULL);
    1.16      assert(list->size < SIZE_MAX / 2);
    1.17 @@ -373,7 +374,15 @@
    1.18  
    1.19      for (ssize_t i = 0; i < (ssize_t) list->size; i++) {
    1.20          if (0 == list->cmpfunc(elem, cur)) {
    1.21 -            return i;
    1.22 +            if (remove) {
    1.23 +                if (0 == cx_arl_remove(list, i)) {
    1.24 +                    return i;
    1.25 +                } else {
    1.26 +                    return -1;
    1.27 +                }
    1.28 +            } else {
    1.29 +                return i;
    1.30 +            }
    1.31          }
    1.32          cur += list->item_size;
    1.33      }
    1.34 @@ -501,7 +510,7 @@
    1.35          cx_arl_clear,
    1.36          cx_arl_swap,
    1.37          cx_arl_at,
    1.38 -        cx_arl_find,
    1.39 +        cx_arl_find_remove,
    1.40          cx_arl_sort,
    1.41          cx_arl_compare,
    1.42          cx_arl_reverse,

mercurial