src/cx/list.h

changeset 640
55cc3b373c5e
parent 638
eafb45eefc51
child 641
d402fead3386
     1.1 --- a/src/cx/list.h	Mon Jan 23 20:34:18 2023 +0100
     1.2 +++ b/src/cx/list.h	Wed Jan 25 19:19:29 2023 +0100
     1.3 @@ -122,33 +122,8 @@
     1.4      void (*destructor)(struct cx_list_s *list);
     1.5  
     1.6      /**
     1.7 -     * Member function for adding an element.
     1.8 -     */
     1.9 -    int (*add)(
    1.10 -            struct cx_list_s *list,
    1.11 -            void const *elem
    1.12 -    );
    1.13 -
    1.14 -    /**
    1.15 -     * Member function for adding multiple elements.
    1.16 -     */
    1.17 -    size_t (*add_array)(
    1.18 -            struct cx_list_s *list,
    1.19 -            void const *array,
    1.20 -            size_t n
    1.21 -    );
    1.22 -
    1.23 -    /**
    1.24 -     * Member function for inserting an element.
    1.25 -     */
    1.26 -    int (*insert)(
    1.27 -            struct cx_list_s *list,
    1.28 -            size_t index,
    1.29 -            void const *elem
    1.30 -    );
    1.31 -
    1.32 -    /**
    1.33       * Member function for inserting multiple elements.
    1.34 +     * Implementors SHOULD see to performant implementations for corner cases.
    1.35       */
    1.36      size_t (*insert_array)(
    1.37              struct cx_list_s *list,
    1.38 @@ -209,20 +184,12 @@
    1.39      void (*reverse)(struct cx_list_s *list);
    1.40  
    1.41      /**
    1.42 -     * Returns an iterator pointing to the specified index.
    1.43 +     * Member function for returning an iterator pointing to the specified index.
    1.44       */
    1.45      struct cx_iterator_s (*iterator)(
    1.46              struct cx_list_s const *list,
    1.47              size_t index
    1.48      );
    1.49 -
    1.50 -    /**
    1.51 -     * Returns a mutating iterator pointing to the specified index.
    1.52 -     */
    1.53 -    struct cx_mut_iterator_s (*mut_iterator)(
    1.54 -            struct cx_list_s *list,
    1.55 -            size_t index
    1.56 -    );
    1.57  };
    1.58  
    1.59  /**
    1.60 @@ -243,7 +210,7 @@
    1.61          CxList *list,
    1.62          void const *elem
    1.63  ) {
    1.64 -    return list->cl->add(list, elem);
    1.65 +    return list->cl->insert_array(list, list->size, elem, 1) != 1;
    1.66  }
    1.67  
    1.68  /**
    1.69 @@ -265,7 +232,7 @@
    1.70          void const *array,
    1.71          size_t n
    1.72  ) {
    1.73 -    return list->cl->add_array(list, array, n);
    1.74 +    return list->cl->insert_array(list, list->size, array, n);
    1.75  }
    1.76  
    1.77  /**
    1.78 @@ -287,7 +254,7 @@
    1.79          size_t index,
    1.80          void const *elem
    1.81  ) {
    1.82 -    return list->cl->insert(list, index, elem);
    1.83 +    return list->cl->insert_array(list, index, elem, 1) != 1;
    1.84  }
    1.85  
    1.86  /**
    1.87 @@ -422,12 +389,10 @@
    1.88   * @return a new iterator
    1.89   */
    1.90  __attribute__((__nonnull__, __warn_unused_result__))
    1.91 -static inline CxMutIterator cxListMutIterator(
    1.92 +CxMutIterator cxListMutIterator(
    1.93          CxList *list,
    1.94          size_t index
    1.95 -) {
    1.96 -    return list->cl->mut_iterator(list, index);
    1.97 -}
    1.98 +);
    1.99  
   1.100  /**
   1.101   * Returns an iterator pointing to the first item of the list.
   1.102 @@ -456,7 +421,7 @@
   1.103   */
   1.104  __attribute__((__nonnull__, __warn_unused_result__))
   1.105  static inline CxMutIterator cxListBeginMut(CxList *list) {
   1.106 -    return list->cl->mut_iterator(list, 0);
   1.107 +    return cxListMutIterator(list, 0);
   1.108  }
   1.109  
   1.110  /**

mercurial