src/cx/list.h

changeset 630
ac5e7f789048
parent 629
6c81ee4f11ad
child 638
eafb45eefc51
     1.1 --- a/src/cx/list.h	Wed Nov 23 22:40:55 2022 +0100
     1.2 +++ b/src/cx/list.h	Sat Nov 26 16:58:41 2022 +0100
     1.3 @@ -151,7 +151,7 @@
     1.4       * Member function for inserting an element relative to an iterator position.
     1.5       */
     1.6      int (*insert_iter)(
     1.7 -            struct cx_iterator_s *iter,
     1.8 +            struct cx_mut_iterator_s *iter,
     1.9              void const *elem,
    1.10              int prepend
    1.11      );
    1.12 @@ -202,6 +202,14 @@
    1.13       * Returns an iterator pointing to the specified index.
    1.14       */
    1.15      struct cx_iterator_s (*iterator)(
    1.16 +            struct cx_list_s const *list,
    1.17 +            size_t index
    1.18 +    );
    1.19 +
    1.20 +    /**
    1.21 +     * Returns a mutating iterator pointing to the specified index.
    1.22 +     */
    1.23 +    struct cx_mut_iterator_s (*mut_iterator)(
    1.24              struct cx_list_s *list,
    1.25              size_t index
    1.26      );
    1.27 @@ -289,7 +297,7 @@
    1.28   */
    1.29  __attribute__((__nonnull__))
    1.30  static inline int cxListInsertAfter(
    1.31 -        CxIterator *iter,
    1.32 +        CxMutIterator *iter,
    1.33          void const *elem
    1.34  ) {
    1.35      return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
    1.36 @@ -312,7 +320,7 @@
    1.37   */
    1.38  __attribute__((__nonnull__))
    1.39  static inline int cxListInsertBefore(
    1.40 -        CxIterator *iter,
    1.41 +        CxMutIterator *iter,
    1.42          void const *elem
    1.43  ) {
    1.44      return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
    1.45 @@ -360,10 +368,29 @@
    1.46   */
    1.47  __attribute__((__nonnull__, __warn_unused_result__))
    1.48  static inline CxIterator cxListIterator(
    1.49 +        CxList const *list,
    1.50 +        size_t index
    1.51 +) {
    1.52 +    return list->cl->iterator(list, index);
    1.53 +}
    1.54 +
    1.55 +/**
    1.56 + * Returns a mutating iterator pointing to the item at the specified index.
    1.57 + *
    1.58 + * The returned iterator is position-aware.
    1.59 + *
    1.60 + * If the index is out of range, a past-the-end iterator will be returned.
    1.61 + *
    1.62 + * @param list the list
    1.63 + * @param index the index where the iterator shall point at
    1.64 + * @return a new iterator
    1.65 + */
    1.66 +__attribute__((__nonnull__, __warn_unused_result__))
    1.67 +static inline CxMutIterator cxListMutIterator(
    1.68          CxList *list,
    1.69          size_t index
    1.70  ) {
    1.71 -    return list->cl->iterator(list, index);
    1.72 +    return list->cl->mut_iterator(list, index);
    1.73  }
    1.74  
    1.75  /**
    1.76 @@ -377,11 +404,26 @@
    1.77   * @return a new iterator
    1.78   */
    1.79  __attribute__((__nonnull__, __warn_unused_result__))
    1.80 -static inline CxIterator cxListBegin(CxList *list) {
    1.81 +static inline CxIterator cxListBegin(CxList const *list) {
    1.82      return list->cl->iterator(list, 0);
    1.83  }
    1.84  
    1.85  /**
    1.86 + * Returns a mutating iterator pointing to the first item of the list.
    1.87 + *
    1.88 + * The returned iterator is position-aware.
    1.89 + *
    1.90 + * If the list is empty, a past-the-end iterator will be returned.
    1.91 + *
    1.92 + * @param list the list
    1.93 + * @return a new iterator
    1.94 + */
    1.95 +__attribute__((__nonnull__, __warn_unused_result__))
    1.96 +static inline CxMutIterator cxListBeginMut(CxList *list) {
    1.97 +    return list->cl->mut_iterator(list, 0);
    1.98 +}
    1.99 +
   1.100 +/**
   1.101   * Returns the index of the first element that equals \p elem.
   1.102   *
   1.103   * Determining equality is performed by the list's comparator function.

mercurial