src/array_list.c

changeset 640
55cc3b373c5e
parent 638
eafb45eefc51
child 641
d402fead3386
     1.1 --- a/src/array_list.c	Mon Jan 23 20:34:18 2023 +0100
     1.2 +++ b/src/array_list.c	Wed Jan 25 19:19:29 2023 +0100
     1.3 @@ -168,23 +168,6 @@
     1.4      cxFree(list->allocator, arl->data);
     1.5  }
     1.6  
     1.7 -static int cx_arl_add(
     1.8 -        struct cx_list_s *list,
     1.9 -        void const *elem
    1.10 -) {
    1.11 -    cx_array_list *arl = (cx_array_list *) list;
    1.12 -    return cx_array_copy(
    1.13 -            &arl->data,
    1.14 -            &list->size,
    1.15 -            &list->capacity,
    1.16 -            list->size,
    1.17 -            elem,
    1.18 -            list->itemsize,
    1.19 -            1,
    1.20 -            &arl->reallocator
    1.21 -    );
    1.22 -}
    1.23 -
    1.24  static size_t cx_arl_insert_array(
    1.25          struct cx_list_s *list,
    1.26          size_t index,
    1.27 @@ -241,48 +224,6 @@
    1.28      }
    1.29  }
    1.30  
    1.31 -static size_t cx_arl_add_array(
    1.32 -        struct cx_list_s *list,
    1.33 -        void const *array,
    1.34 -        size_t n
    1.35 -) {
    1.36 -    return cx_arl_insert_array(list, list->size, array, n);
    1.37 -}
    1.38 -
    1.39 -static int cx_arl_insert(
    1.40 -        struct cx_list_s *list,
    1.41 -        size_t index,
    1.42 -        void const *elem
    1.43 -) {
    1.44 -    if (index > list->size) {
    1.45 -        return 1;
    1.46 -    } else if (index == list->size) {
    1.47 -        return cx_arl_add(list, elem);
    1.48 -    } else {
    1.49 -        cx_array_list *arl = (cx_array_list *) list;
    1.50 -
    1.51 -        // move elements starting at index to the right
    1.52 -        if (cx_array_copy(
    1.53 -                &arl->data,
    1.54 -                &list->size,
    1.55 -                &list->capacity,
    1.56 -                index + 1,
    1.57 -                ((char *) arl->data) + index * list->itemsize,
    1.58 -                list->itemsize,
    1.59 -                list->size - index,
    1.60 -                &arl->reallocator
    1.61 -        )) {
    1.62 -            return 1;
    1.63 -        }
    1.64 -
    1.65 -        // place the element
    1.66 -        memcpy(((char *) arl->data) + index * list->itemsize,
    1.67 -               elem, list->itemsize);
    1.68 -
    1.69 -        return 0;
    1.70 -    }
    1.71 -}
    1.72 -
    1.73  static int cx_arl_insert_iter(
    1.74          struct cx_mut_iterator_s *iter,
    1.75          void const *elem,
    1.76 @@ -290,10 +231,11 @@
    1.77  ) {
    1.78      struct cx_list_s *list = iter->src_handle;
    1.79      if (iter->index < list->size) {
    1.80 -        int result = cx_arl_insert(
    1.81 +        int result = 1 != cx_arl_insert_array(
    1.82                  list,
    1.83                  iter->index + 1 - prepend,
    1.84 -                elem
    1.85 +                elem,
    1.86 +                1
    1.87          );
    1.88          if (result == 0 && prepend != 0) {
    1.89              iter->index++;
    1.90 @@ -301,7 +243,7 @@
    1.91          }
    1.92          return result;
    1.93      } else {
    1.94 -        int result = cx_arl_add(list, elem);
    1.95 +        int result = 1 != cx_arl_insert_array(list, list->size, elem, 1);
    1.96          iter->index = list->size;
    1.97          return result;
    1.98      }
    1.99 @@ -463,24 +405,8 @@
   1.100      return iter;
   1.101  }
   1.102  
   1.103 -static struct cx_mut_iterator_s cx_arl_mut_iterator(
   1.104 -        struct cx_list_s *list,
   1.105 -        size_t index
   1.106 -) {
   1.107 -    CxIterator it = cx_arl_iterator(list, index);
   1.108 -    it.base.mutating = true;
   1.109 -
   1.110 -    // we know the iterators share the same memory layout
   1.111 -    CxMutIterator iter;
   1.112 -    memcpy(&iter, &it, sizeof(CxMutIterator));
   1.113 -    return iter;
   1.114 -}
   1.115 -
   1.116  static cx_list_class cx_array_list_class = {
   1.117          cx_arl_destructor,
   1.118 -        cx_arl_add,
   1.119 -        cx_arl_add_array,
   1.120 -        cx_arl_insert,
   1.121          cx_arl_insert_array,
   1.122          cx_arl_insert_iter,
   1.123          cx_arl_remove,
   1.124 @@ -490,7 +416,6 @@
   1.125          cx_arl_compare,
   1.126          cx_arl_reverse,
   1.127          cx_arl_iterator,
   1.128 -        cx_arl_mut_iterator,
   1.129  };
   1.130  
   1.131  CxList *cxArrayListCreate(

mercurial