ucx/cx/list.h

branch
newapi
changeset 253
087cc9216f28
parent 187
24ce2c326d85
--- a/ucx/cx/list.h	Sun Feb 11 15:44:33 2024 +0100
+++ b/ucx/cx/list.h	Sun Feb 11 22:06:23 2024 +0100
@@ -30,7 +30,6 @@
  * \brief Interface for list implementations.
  * \author Mike Becker
  * \author Olaf Wintermann
- * \version 3.0
  * \copyright 2-Clause BSD License
  */
 
@@ -137,11 +136,12 @@
     );
 
     /**
-     * Member function for finding an element.
+     * Member function for finding and optionally removing an element.
      */
-    ssize_t (*find)(
-            struct cx_list_s const *list,
-            void const *elem
+    ssize_t (*find_remove)(
+            struct cx_list_s *list,
+            void const *elem,
+            bool remove
     );
 
     /**
@@ -580,7 +580,25 @@
         CxList const *list,
         void const *elem
 ) {
-    return list->cl->find(list, elem);
+    return list->cl->find_remove((CxList*)list, elem, false);
+}
+
+/**
+ * Removes and returns the index of the first element that equals \p elem.
+ *
+ * Determining equality is performed by the list's comparator function.
+ *
+ * @param list the list
+ * @param elem the element to find and remove
+ * @return the index of the now removed element or a negative
+ * value when the element is not found or could not be removed
+ */
+__attribute__((__nonnull__))
+static inline ssize_t cxListFindRemove(
+        CxList *list,
+        void const *elem
+) {
+    return list->cl->find_remove(list, elem, true);
 }
 
 /**

mercurial