diff -r ec1f2015ec79 -r 75da57d4634e src/cx/linked_list.h --- a/src/cx/linked_list.h Sun Oct 06 19:17:41 2024 +0200 +++ b/src/cx/linked_list.h Mon Oct 07 20:20:21 2024 +0200 @@ -389,6 +389,37 @@ ); /** + * Removes a chain of nodes from the linked list. + * + * If one of the nodes to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end) + * addresses are provided, the pointers are adjusted accordingly. + * + * The following combinations of arguments are valid (more arguments are optional): + * \li \p loc_next and \p loc_prev (ancestor node is determined by using the prev pointer, overall O(1) performance) + * \li \p loc_next and \p begin (ancestor node is determined by list traversal, overall O(n) performance) + * + * \remark The \c next and \c prev pointers of the removed node are not cleared by this function and may still be used + * to traverse to a former adjacent node in the list, or within the chain. + * + * @param begin a pointer to the begin node pointer (optional) + * @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 your struct does not have one) + * @param loc_next the location of a \c next pointer within your node struct (required) + * @param node the start node of the chain + * @param num the number of nodes to remove + * @return the actual number of nodes that were removed (may be less when the list did not have enough nodes) + */ +__attribute__((__nonnull__(5))) +size_t cx_linked_list_remove_chain( + void **begin, + void **end, + ptrdiff_t loc_prev, + ptrdiff_t loc_next, + void *node, + size_t num +); + +/** * Removes a node from the linked list. * * If the node to remove is the begin (resp. end) node of the list and if \p begin (resp. \p end) @@ -408,14 +439,15 @@ * @param node the node to remove */ __attribute__((__nonnull__(5))) -void cx_linked_list_remove( +static inline void cx_linked_list_remove( void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node -); - +) { + cx_linked_list_remove_chain(begin, end, loc_prev, loc_next, node, 1); +} /** * Determines the size of a linked list starting with \p node.