src/cx/list.h

changeset 1101
2872f287fadc
parent 993
b642eca4b956
child 1109
89ec23988b88
--- a/src/cx/list.h	Sun Jan 05 11:51:11 2025 +0100
+++ b/src/cx/list.h	Sun Jan 05 12:07:39 2025 +0100
@@ -26,11 +26,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /**
- * \file list.h
- * \brief Interface for list implementations.
- * \author Mike Becker
- * \author Olaf Wintermann
- * \copyright 2-Clause BSD License
+ * @file list.h
+ * @brief Interface for list implementations.
+ * @author Mike Becker
+ * @author Olaf Wintermann
+ * @copyright 2-Clause BSD License
  */
 
 #ifndef UCX_LIST_H
@@ -76,14 +76,12 @@
      * Implementations SHALL invoke the content destructor functions if provided
      * and SHALL deallocate the entire list memory.
      */
-    cx_attr_nonnull
     void (*deallocate)(struct cx_list_s *list);
 
     /**
      * Member function for inserting a single element.
      * Implementors SHOULD see to performant implementations for corner cases.
      */
-    cx_attr_nonnull
     int (*insert_element)(
             struct cx_list_s *list,
             size_t index,
@@ -93,9 +91,9 @@
     /**
      * Member function for inserting multiple elements.
      * Implementors SHOULD see to performant implementations for corner cases.
+     *
      * @see cx_list_default_insert_array()
      */
-    cx_attr_nonnull
     size_t (*insert_array)(
             struct cx_list_s *list,
             size_t index,
@@ -108,7 +106,6 @@
      *
      * @see cx_list_default_insert_sorted()
      */
-    cx_attr_nonnull
     size_t (*insert_sorted)(
             struct cx_list_s *list,
             const void *sorted_data,
@@ -118,7 +115,6 @@
     /**
      * Member function for inserting an element relative to an iterator position.
      */
-    cx_attr_nonnull
     int (*insert_iter)(
             struct cx_iterator_s *iter,
             const void *elem,
@@ -128,15 +124,13 @@
     /**
      * Member function for removing elements.
      *
-     * Implementations SHALL check if \p targetbuf is set and copy the elements
+     * Implementations SHALL check if @p targetbuf is set and copy the elements
      * to the buffer without invoking any destructor.
-     * When \p targetbuf is not set, the destructors SHALL be invoked.
+     * When @p targetbuf is not set, the destructors SHALL be invoked.
      *
      * The function SHALL return the actual number of elements removed, which
-     * might be lower than \p num when going out of bounds.
+     * might be lower than @p num when going out of bounds.
      */
-    cx_attr_nonnull_arg(1)
-    cx_attr_access_w(4)
     size_t (*remove)(
             struct cx_list_s *list,
             size_t index,
@@ -147,14 +141,13 @@
     /**
      * Member function for removing all elements.
      */
-    cx_attr_nonnull
     void (*clear)(struct cx_list_s *list);
 
     /**
      * Member function for swapping two elements.
+     *
      * @see cx_list_default_swap()
      */
-    cx_attr_nonnull
     int (*swap)(
             struct cx_list_s *list,
             size_t i,
@@ -164,8 +157,6 @@
     /**
      * Member function for element lookup.
      */
-    cx_attr_nonnull
-    cx_attr_nodiscard
     void *(*at)(
             const struct cx_list_s *list,
             size_t index
@@ -174,8 +165,6 @@
     /**
      * Member function for finding and optionally removing an element.
      */
-    cx_attr_nonnull
-    cx_attr_nodiscard
     ssize_t (*find_remove)(
             struct cx_list_s *list,
             const void *elem,
@@ -183,16 +172,16 @@
     );
 
     /**
-     * Member function for sorting the list in-place.
+     * Member function for sorting the list.
+     *
      * @see cx_list_default_sort()
      */
-    cx_attr_nonnull
     void (*sort)(struct cx_list_s *list);
 
     /**
      * Optional member function for comparing this list
      * to another list of the same type.
-     * If set to \c NULL, comparison won't be optimized.
+     * If set to @c NULL, comparison won't be optimized.
      */
     cx_attr_nonnull
     int (*compare)(
@@ -203,13 +192,11 @@
     /**
      * Member function for reversing the order of the items.
      */
-    cx_attr_nonnull
     void (*reverse)(struct cx_list_s *list);
 
     /**
      * Member function for returning an iterator pointing to the specified index.
      */
-    cx_attr_nonnull
     struct cx_iterator_s (*iterator)(
             const struct cx_list_s *list,
             size_t index,
@@ -245,7 +232,7 @@
  * This function uses the array insert function to insert consecutive groups
  * of sorted data.
  *
- * The source data \em must already be sorted wrt. the list's compare function.
+ * The source data @em must already be sorted wrt. the list's compare function.
  *
  * Use this in your own list class if you do not want to implement an optimized
  * version for your list.
@@ -285,7 +272,8 @@
  * @param list the list in which to swap
  * @param i index of one element
  * @param j index of the other element
- * @return zero on success, non-zero when indices are out of bounds or memory
+ * @retval zero success
+ * @retval non-zero when indices are out of bounds or memory
  * allocation for the temporary buffer fails
  */
 cx_attr_nonnull
@@ -351,7 +339,8 @@
  *
  * @param list the list
  * @param elem a pointer to the element to add
- * @return zero on success, non-zero on memory allocation failure
+ * @retval zero success
+ * @retval non-zero memory allocation failure
  * @see cxListAddArray()
  */
 cx_attr_nonnull
@@ -368,9 +357,9 @@
  * This method is more efficient than invoking cxListAdd() multiple times.
  *
  * If there is not enough memory to add all elements, the returned value is
- * less than \p n.
+ * less than @p n.
  *
- * If this list is storing pointers instead of objects \p array is expected to
+ * If this list is storing pointers instead of objects @p array is expected to
  * be an array of pointers.
  *
  * @param list the list
@@ -390,13 +379,13 @@
 /**
  * Inserts an item at the specified index.
  *
- * If \p index equals the list \c size, this is effectively cxListAdd().
+ * If @p index equals the list @c size, this is effectively cxListAdd().
  *
  * @param list the list
  * @param index the index the element shall have
  * @param elem a pointer to the element to add
- * @return zero on success, non-zero on memory allocation failure
- * or when the index is out of bounds
+ * @retval zero success
+ * @retval non-zero memory allocation failure or the index is out of bounds
  * @see cxListInsertAfter()
  * @see cxListInsertBefore()
  */
@@ -414,7 +403,8 @@
  *
  * @param list the list
  * @param elem a pointer to the element to add
- * @return zero on success, non-zero on memory allocation failure
+ * @retval zero success
+ * @retval non-zero memory allocation failure
  */
 cx_attr_nonnull
 static inline int cxListInsertSorted(
@@ -427,15 +417,15 @@
 
 /**
  * Inserts multiple items to the list at the specified index.
- * If \p index equals the list size, this is effectively cxListAddArray().
+ * If @p index equals the list size, this is effectively cxListAddArray().
  *
  * This method is usually more efficient than invoking cxListInsert()
  * multiple times.
  *
  * If there is not enough memory to add all elements, the returned value is
- * less than \p n.
+ * less than @p n.
  *
- * If this list is storing pointers instead of objects \p array is expected to
+ * If this list is storing pointers instead of objects @p array is expected to
  * be an array of pointers.
  *
  * @param list the list
@@ -461,9 +451,9 @@
  * because consecutive chunks of sorted data are inserted in one pass.
  *
  * If there is not enough memory to add all elements, the returned value is
- * less than \p n.
+ * less than @p n.
  *
- * If this list is storing pointers instead of objects \p array is expected to
+ * If this list is storing pointers instead of objects @p array is expected to
  * be an array of pointers.
  *
  * @param list the list
@@ -486,12 +476,13 @@
  * The used iterator remains operational, but all other active iterators should
  * be considered invalidated.
  *
- * If \p iter is not a list iterator, the behavior is undefined.
- * If \p iter is a past-the-end iterator, the new element gets appended to the list.
+ * If @p iter is not a list iterator, the behavior is undefined.
+ * If @p iter is a past-the-end iterator, the new element gets appended to the list.
  *
  * @param iter an iterator
  * @param elem the element to insert
- * @return zero on success, non-zero on memory allocation failure
+ * @retval zero success
+ * @retval non-zero memory allocation failure
  * @see cxListInsert()
  * @see cxListInsertBefore()
  */
@@ -509,12 +500,13 @@
  * The used iterator remains operational, but all other active iterators should
  * be considered invalidated.
  *
- * If \p iter is not a list iterator, the behavior is undefined.
- * If \p iter is a past-the-end iterator, the new element gets appended to the list.
+ * If @p iter is not a list iterator, the behavior is undefined.
+ * If @p iter is a past-the-end iterator, the new element gets appended to the list.
  *
  * @param iter an iterator
  * @param elem the element to insert
- * @return zero on success, non-zero on memory allocation failure
+ * @retval zero success
+ * @retval non-zero memory allocation failure
  * @see cxListInsert()
  * @see cxListInsertAfter()
  */
@@ -534,7 +526,8 @@
  *
  * @param list the list
  * @param index the index of the element
- * @return zero on success, non-zero if the index is out of bounds
+ * @retval zero success
+ * @retval non-zero index out of bounds
  */
 cx_attr_nonnull
 static inline int cxListRemove(
@@ -548,12 +541,13 @@
  * Removes and returns the element at the specified index.
  *
  * No destructor is called and instead the element is copied to the
- * \p targetbuf which MUST be large enough to hold the removed element.
+ * @p targetbuf which MUST be large enough to hold the removed element.
  *
  * @param list the list
  * @param index the index of the element
  * @param targetbuf a buffer where to copy the element
- * @return zero on success, non-zero if the index is out of bounds
+ * @retval zero success
+ * @retval non-zero index out of bounds
  */
 cx_attr_nonnull
 cx_attr_access_w(3)
@@ -593,7 +587,7 @@
  * Removes and returns multiple element starting at the specified index.
  *
  * No destructor is called and instead the elements are copied to the
- * \p targetbuf which MUST be large enough to hold all removed elements.
+ * @p targetbuf which MUST be large enough to hold all removed elements.
  *
  * @param list the list
  * @param index the index of the element
@@ -615,7 +609,7 @@
 /**
  * Removes all elements from this list.
  *
- * If an element destructor function is specified, it is called for each
+ * If element destructor functions are specified, they are called for each
  * element before removing them.
  *
  * @param list the list
@@ -634,7 +628,9 @@
  * @param list the list
  * @param i the index of the first element
  * @param j the index of the second element
- * @return zero on success, non-zero if one of the indices is out of bounds
+ * @retval zero success
+ * @retval non-zero one of the indices is out of bounds
+ * or the swap needed extra memory but allocation failed
  */
 cx_attr_nonnull
 static inline int cxListSwap(
@@ -650,7 +646,7 @@
  *
  * @param list the list
  * @param index the index of the element
- * @return a pointer to the element or \c NULL if the index is out of bounds
+ * @return a pointer to the element or @c NULL if the index is out of bounds
  */
 cx_attr_nonnull
 static inline void *cxListAt(
@@ -803,7 +799,7 @@
 }
 
 /**
- * Returns the index of the first element that equals \p elem.
+ * Returns the index of the first element that equals @p elem.
  *
  * Determining equality is performed by the list's comparator function.
  *
@@ -822,7 +818,7 @@
 }
 
 /**
- * Removes and returns the index of the first element that equals \p elem.
+ * Removes and returns the index of the first element that equals @p elem.
  *
  * Determining equality is performed by the list's comparator function.
  *
@@ -840,9 +836,9 @@
 }
 
 /**
- * Sorts the list in-place.
+ * Sorts the list.
  *
- * \remark The underlying sort algorithm is implementation defined.
+ * @remark The underlying sort algorithm is implementation defined.
  *
  * @param list the list
  */
@@ -869,8 +865,11 @@
  *
  * @param list the list
  * @param other the list to compare to
- * @return zero, if both lists are equal element wise,
- * negative if the first list is smaller, positive if the first list is larger
+ * @retval zero both lists are equal element wise
+ * @retval negative the first list is smaller
+ * or the first non-equal element in the first list is smaller
+ * @retval positive the first list is larger
+ * or the first non-equal element in the first list is larger
  */
 cx_attr_nonnull
 cx_attr_nodiscard
@@ -882,7 +881,7 @@
 /**
  * Deallocates the memory of the specified list structure.
  *
- * Also calls the content destructor function for each element, if specified.
+ * Also calls the content destructor functions for each element, if specified.
  *
  * @param list the list which shall be freed
  */
@@ -895,6 +894,9 @@
  * A shared instance of an empty list.
  *
  * Writing to that list is not allowed.
+ *
+ * You can use this is a placeholder for initializing CxList pointers
+ * for which you do not want to reserve memory right from the beginning.
  */
 extern CxList *const cxEmptyList;
 

mercurial