1.1 --- a/src/cx/linked_list.h Sat Oct 09 11:12:48 2021 +0200 1.2 +++ b/src/cx/linked_list.h Sat Dec 04 17:38:23 2021 +0100 1.3 @@ -97,17 +97,30 @@ 1.4 void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index); 1.5 1.6 /** 1.7 + * Finds the first node in a linked list. 1.8 + * 1.9 + * The function starts with the pointer denoted by \p node and traverses the list 1.10 + * along a prev pointer whose location within the node struct is 1.11 + * denoted by \p loc_prev. 1.12 + * 1.13 + * @param node a pointer to a node in the list 1.14 + * @param loc_prev the location of the \c prev pointer 1.15 + * @return a pointer to the first node or \c NULL if \p node is \c NULL 1.16 + */ 1.17 +void *cx_linked_list_first(void *node, ptrdiff_t loc_prev); 1.18 + 1.19 +/** 1.20 * Finds the last node in a linked list. 1.21 * 1.22 - * The function starts with the pointer denoted by \p begin and traverses the list 1.23 + * The function starts with the pointer denoted by \p node and traverses the list 1.24 * along a next pointer whose location within the node struct is 1.25 * denoted by \p loc_next. 1.26 * 1.27 - * @param begin a pointer to the begin node 1.28 + * @param node a pointer to a node in the list 1.29 * @param loc_next the location of the \c next pointer 1.30 * @return a pointer to the last node or \c NULL if \p begin is \c NULL 1.31 */ 1.32 -void *cx_linked_list_last(void *begin, ptrdiff_t loc_next); 1.33 +void *cx_linked_list_last(void *node, ptrdiff_t loc_next); 1.34 1.35 /** 1.36 * Finds the predecessor of a node in case it is not linked. 1.37 @@ -123,6 +136,7 @@ 1.38 1.39 /** 1.40 * Adds a new node to a linked list. 1.41 + * The node must not be part of any list already. 1.42 * 1.43 * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. 1.44 * 1.45 @@ -135,6 +149,20 @@ 1.46 void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.47 1.48 /** 1.49 + * Prepends a new node to a linked list. 1.50 + * The node must not be part of any list already. 1.51 + * 1.52 + * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. 1.53 + * 1.54 + * @param begin a pointer to the begin node pointer (if your list has one) 1.55 + * @param end a pointer to the end node pointer (if your list has one) 1.56 + * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 1.57 + * @param loc_next the location of a \c next pointer within your node struct (required) 1.58 + * @param new_node a pointer to the node that shall be prepended 1.59 + */ 1.60 +void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.61 + 1.62 +/** 1.63 * Removes a node from the linked list. 1.64 * 1.65 * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end)