src/cx/list.h

changeset 638
eafb45eefc51
parent 630
ac5e7f789048
child 640
55cc3b373c5e
     1.1 --- a/src/cx/list.h	Mon Jan 23 20:00:26 2023 +0100
     1.2 +++ b/src/cx/list.h	Mon Jan 23 20:22:11 2023 +0100
     1.3 @@ -148,6 +148,16 @@
     1.4      );
     1.5  
     1.6      /**
     1.7 +     * Member function for inserting multiple elements.
     1.8 +     */
     1.9 +    size_t (*insert_array)(
    1.10 +            struct cx_list_s *list,
    1.11 +            size_t index,
    1.12 +            void const *data,
    1.13 +            size_t n
    1.14 +    );
    1.15 +
    1.16 +    /**
    1.17       * Member function for inserting an element relative to an iterator position.
    1.18       */
    1.19      int (*insert_iter)(
    1.20 @@ -281,6 +291,32 @@
    1.21  }
    1.22  
    1.23  /**
    1.24 + * Inserts multiple items to the list at the specified index.
    1.25 + * If \p index equals the list size, this is effectively cxListAddArray().
    1.26 + *
    1.27 + * This method is usually more efficient than invoking cxListInsert()
    1.28 + * multiple times.
    1.29 + *
    1.30 + * If there is not enough memory to add all elements, the returned value is
    1.31 + * less than \p n.
    1.32 + *
    1.33 + * @param list the list
    1.34 + * @param index the index where to add the elements
    1.35 + * @param array a pointer to the elements to add
    1.36 + * @param n the number of elements to add
    1.37 + * @return the number of added elements
    1.38 + */
    1.39 +__attribute__((__nonnull__))
    1.40 +static inline size_t cxListInsertArray(
    1.41 +        CxList *list,
    1.42 +        size_t index,
    1.43 +        void const *array,
    1.44 +        size_t n
    1.45 +) {
    1.46 +    return list->cl->insert_array(list, index, array, n);
    1.47 +}
    1.48 +
    1.49 +/**
    1.50   * Inserts an element after the current location of the specified iterator.
    1.51   *
    1.52   * The used iterator remains operational, but all other active iterators should

mercurial