1.1 --- a/src/cx/linked_list.h Tue Oct 05 13:04:20 2021 +0200 1.2 +++ b/src/cx/linked_list.h Tue Oct 05 16:33:11 2021 +0200 1.3 @@ -122,6 +122,46 @@ 1.4 */ 1.5 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.6 1.7 +/** 1.8 + * Determines the size of a linked list starting with \p node. 1.9 + * @param node the first node 1.10 + * @param loc_next the location of the \c next pointer within the node struct 1.11 + * @return the size of the list or zero if \p node is \c NULL 1.12 + */ 1.13 +size_t cx_linked_list_size(void *node, ptrdiff_t loc_next); 1.14 + 1.15 +/** 1.16 + * Sorts a linked list based on a comparison function. 1.17 + * 1.18 + * This function can work with linked lists of the following structures: 1.19 + * \code 1.20 + * typedef struct node node; 1.21 + * struct node { 1.22 + * node* prev; 1.23 + * node* next; 1.24 + * my_payload data; // in this case set follow_ptr = 0 1.25 + * } 1.26 + * 1.27 + * typedef struct ptr_node ptr_node; 1.28 + * struct ptr_node { 1.29 + * ptr_node* prev; 1.30 + * ptr_node* next; 1.31 + * my_payload* data; // in this case set follow_ptr = 1 1.32 + * } 1.33 + * \endcode 1.34 + * 1.35 + * @param begin a pointer to the begin node pointer (required) 1.36 + * @param end a pointer to the end node pointer (optional) 1.37 + * @param loc_prev the location of a \c prev pointer within your node struct (negative if not present) 1.38 + * @param loc_next the location of a \c next pointer within your node struct (required) 1.39 + * @param loc_data the location of the \c data pointer within your node struct 1.40 + * @param follow_ptr \c false if the pointer denoted by \p loc_data shall be passed to the \p cmp_func. 1.41 + * If \c true, the data at \p loc_data is dereferenced, assuming to be a pointer, and then passed to \p cmp_func. 1.42 + * @param cmp_func the compare function defining the sort order 1.43 + */ 1.44 +void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, 1.45 + ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func); 1.46 + 1.47 #ifdef __cplusplus 1.48 } /* extern "C" */ 1.49 #endif