diff -r 95e42a963520 -r 75ae1dccd101 src/cx/linked_list.h --- a/src/cx/linked_list.h Tue Oct 05 13:04:20 2021 +0200 +++ b/src/cx/linked_list.h Tue Oct 05 16:33:11 2021 +0200 @@ -122,6 +122,46 @@ */ void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); +/** + * Determines the size of a linked list starting with \p node. + * @param node the first node + * @param loc_next the location of the \c next pointer within the node struct + * @return the size of the list or zero if \p node is \c NULL + */ +size_t cx_linked_list_size(void *node, ptrdiff_t loc_next); + +/** + * Sorts a linked list based on a comparison function. + * + * This function can work with linked lists of the following structures: + * \code + * typedef struct node node; + * struct node { + * node* prev; + * node* next; + * my_payload data; // in this case set follow_ptr = 0 + * } + * + * typedef struct ptr_node ptr_node; + * struct ptr_node { + * ptr_node* prev; + * ptr_node* next; + * my_payload* data; // in this case set follow_ptr = 1 + * } + * \endcode + * + * @param begin a pointer to the begin node pointer (required) + * @param end a pointer to the end node pointer (optional) + * @param loc_prev the location of a \c prev pointer within your node struct (negative if not present) + * @param loc_next the location of a \c next pointer within your node struct (required) + * @param loc_data the location of the \c data pointer within your node struct + * @param follow_ptr \c false if the pointer denoted by \p loc_data shall be passed to the \p cmp_func. + * If \c true, the data at \p loc_data is dereferenced, assuming to be a pointer, and then passed to \p cmp_func. + * @param cmp_func the compare function defining the sort order + */ +void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, + ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func); + #ifdef __cplusplus } /* extern "C" */ #endif