--- a/docs/Writerside/topics/linked_list.h.md Fri Oct 10 12:26:43 2025 +0200 +++ b/docs/Writerside/topics/linked_list.h.md Fri Oct 10 17:24:19 2025 +0200 @@ -115,6 +115,14 @@ void cx_linked_list_insert_sorted_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); + +int cx_linked_list_insert_unique(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *new_node, cx_compare_func cmp_func); + +void *cx_linked_list_insert_unique_chain(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *insert_begin, cx_compare_func cmp_func); ``` The above functions can be used to insert one or more elements into a linked list. @@ -136,6 +144,12 @@ except that `begin` and `loc_next` are always required, and the target list must already be sorted. The order is determined by the `cmp_func` to which the pointers to the nodes are passed. +The functions `cx_linked_list_insert_unique()` and `cx_linked_list_insert_unique_chain()` are similar to +`cx_linked_list_insert_sorted()` and `cx_linked_list_insert_sorted_chain()`, except that they only insert the node +if it is not already contained in the list. +When a duplicate is found, `cx_linked_list_insert_unique()` returns non-zero and `cx_linked_list_insert_unique_chain()` +returns a pointer to a new chain starting with the first node that was not inserted. + > The `cx_linked_list_insert_sorted_chain()` function does not have an `insert_end` argument, because > it cannot take advantage of simply inserting the entire chain as-is, as the chain might need to be broken > to maintain the sort order.