1.1 --- a/src/cx/linked_list.h Fri Oct 08 18:58:49 2021 +0200 1.2 +++ b/src/cx/linked_list.h Fri Oct 08 19:47:31 2021 +0200 1.3 @@ -110,6 +110,18 @@ 1.4 void *cx_linked_list_last(void *begin, ptrdiff_t loc_next); 1.5 1.6 /** 1.7 + * Finds the predecessor of a node in case it is not linked. 1.8 + * 1.9 + * \remark If \p node is not contained in the list starting with \p begin, the behavior is undefined. 1.10 + * 1.11 + * @param begin the node where to start the search 1.12 + * @param loc_next the location of the \c next pointer 1.13 + * @param node the successor of the node to find 1.14 + * @return the node or \c NULL if \p node has no predecessor 1.15 + */ 1.16 +void *cx_linked_list_prev(void *begin, ptrdiff_t loc_next, void *node); 1.17 + 1.18 +/** 1.19 * Adds a new node to a linked list. 1.20 * 1.21 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. 1.22 @@ -117,12 +129,38 @@ 1.23 * @param begin a pointer to the begin node pointer (if your list has one) 1.24 * @param end a pointer to the end node pointer (if your list has one) 1.25 * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 1.26 - * @param loc_next the location of a \c next pointer within your node struct (negative if your struct does not have one) 1.27 + * @param loc_next the location of a \c next pointer within your node struct (required) 1.28 * @param new_node a pointer to the node that shall be appended 1.29 */ 1.30 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.31 1.32 /** 1.33 + * Removes a node from the linked list. 1.34 + * 1.35 + * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end) 1.36 + * addresses are provided, the pointers are adjusted accordingly. 1.37 + * 1.38 + * The following combinations of arguments are valid (more arguments are optional): 1.39 + * \li \p loc_next and \p loc_prev 1.40 + * \li \p loc_next and \p begin 1.41 + * 1.42 + * This function returns an adjacent node according to the following rules: 1.43 + * \li if the node has only one adjacent node, that one is returned 1.44 + * \li otherwise, the former \c prev node is returned 1.45 + * 1.46 + * \remark The \c next and \c prev pointers of the removed node are cleared by this function. 1.47 + * 1.48 + * @param begin a pointer to the begin node pointer (optional) 1.49 + * @param end a pointer to the end node pointer (optional) 1.50 + * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 1.51 + * @param loc_next the location of a \c next pointer within your node struct (required) 1.52 + * @param node the node to remove 1.53 + * @return an adjacent node or \c NULL, if this was the last node 1.54 + */ 1.55 +void *cx_linked_list_remove(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node); 1.56 + 1.57 + 1.58 +/** 1.59 * Determines the size of a linked list starting with \p node. 1.60 * @param node the first node 1.61 * @param loc_next the location of the \c next pointer within the node struct 1.62 @@ -162,6 +200,17 @@ 1.63 void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, 1.64 ptrdiff_t loc_data, int follow_ptr, CxListComparator cmp_func); 1.65 1.66 + 1.67 +/** 1.68 + * Reverses the order of the nodes in a linked list. 1.69 + * 1.70 + * @param begin a pointer to the begin node pointer (required) 1.71 + * @param end a pointer to the end node pointer (optional) 1.72 + * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 1.73 + * @param loc_next the location of a \c next pointer within your node struct (required) 1.74 + */ 1.75 +void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next); 1.76 + 1.77 #ifdef __cplusplus 1.78 } /* extern "C" */ 1.79 #endif