--- a/docs/Writerside/topics/linked_list.h.md Fri Dec 19 18:31:26 2025 +0100 +++ b/docs/Writerside/topics/linked_list.h.md Sat Dec 20 10:43:14 2025 +0100 @@ -137,6 +137,22 @@ 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); + +void cx_linked_list_insert_sorted_c(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *new_node, cx_compare_func2 cmp_func, void *context); + +void cx_linked_list_insert_sorted_chain_c(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *insert_begin, cx_compare_func2 cmp_func, void *context); + +int cx_linked_list_insert_unique_c(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *new_node, cx_compare_func2 cmp_func, void *context); + +void *cx_linked_list_insert_unique_chain_c(void **begin, void **end, + ptrdiff_t loc_prev, ptrdiff_t loc_next, + void *insert_begin, cx_compare_func2 cmp_func, void *context); ``` The above functions can be used to insert one or more elements into a linked list. @@ -168,6 +184,8 @@ > 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. +The functions with the `_c` suffix are equivalent, except that they accept a `cx_compare_func2` with additional `context`. + ## Access and Find ```C @@ -298,14 +316,14 @@ ); ``` -For comparing two linked list, you need to specify where to start, +For comparing two linked lists, you need to specify where to start, and the offsets for the pointer to the next node and the data. In the natural case, `begin_left` and `begin_right` point to the first node of either list, and `loc_advance` is the offset of the `next` pointer. But it is also possible to start with the _last_ node of both lists and use the `prev` pointer to compare them backwards. -The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_fnc`. +The `loc_data` offset is used to calculate the pointer that is passed to the `cmp_func`. This can either be the offset of a specific field in the struct or simply zero, in which case the pointers to the nodes themselves are passed to the compare function. The function `cx_linked_list_compare_c()` allows additional `context` for the compare function.