src/cx/list.h

changeset 1453
b6fc5b1d5c5d
parent 1444
dd9dcbb39c2f
--- a/src/cx/list.h	Sun Oct 26 15:51:49 2025 +0100
+++ b/src/cx/list.h	Sun Oct 26 16:16:43 2025 +0100
@@ -983,6 +983,34 @@
 CX_EXPORT int cxListClone(CxList *dst, const CxList *src,
         cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
 
+/**
+ * Clones elements from a list only if they are not present in another list.
+ *
+ * If the @p minuend does not contain duplicates, this is equivalent to adding
+ * the set difference to the destination list.
+ *
+ * If the destination list already contains elements, the difference
+ * (@p dst + @p minuend) - @p subtrahend is calculated.
+ * New items for @p dst are always appendend to the list, which means that the
+ * destination list is not necessarily sorted.
+ *
+ * This function is optimized for the case when both the @p minuend and the
+ * @p subtrahend are sorted.
+ *
+ * @param dst the destination list
+ * @param minuend the list to subtract elements from
+ * @param subtrahend the elements that shall be subtracted
+ * @param clone_func the clone function for the elements
+ * @param clone_allocator the allocator that is passed to the clone function
+ * @param data optional additional data that is passed to the clone function
+ * @retval zero when the elements were successfully cloned
+ * @retval non-zero when an allocation error occurred
+ */
+cx_attr_nonnull_arg(1, 2, 3)
+CX_EXPORT int cxListDifference(CxList *dst,
+        const CxList *minuend, const CxList *subtrahend,
+        cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif

mercurial