diff -r a10c3e127050 -r bb144d08cd44 src/cx/linked_list.h --- a/src/cx/linked_list.h Sun Oct 03 13:07:48 2021 +0200 +++ b/src/cx/linked_list.h Sun Oct 03 14:06:57 2021 +0200 @@ -25,6 +25,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +/** + * \file linked_list.h + * \brief Linked list implementation. + * \details Also provides several low-level functions for custom linked list implementations. + * \author Mike Becker + * \author Olaf Wintermann + * \version 3.0 + * \copyright 2-Clause BSD License + */ #ifndef UCX_LINKED_LIST_H #define UCX_LINKED_LIST_H @@ -36,6 +45,13 @@ extern "C" { #endif +CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size); + +void cxLinkedListDestroy(CxList list); + +size_t cxLinkedListRecalculateSize(CxList list); + + /** * Finds the node at a certain index. * @@ -55,17 +71,35 @@ */ void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index); +/** + * Finds the last node in a linked list. + * + * If a pointer to \p end is provided, the result is just \c *end. + * Otherwise, this function starts with the pointer denoted by \c *begin and + * traverses the list along a next pointer whose location within the node struct is + * denoted by \p loc_next. + * + * If both \p begin and \p end are \c NULL, an empty list is assumed and this function returns \c NULL. + * + * @param begin a pointer to the begin node pointer (optional) + * @param end a pointer to the end node pointer (optional) + * @param loc_next the location of the \c next pointer (only required when \p end is \c NULL) + * @return a pointer to the last node or \c NULL if the list is empty + */ void *cx_linked_list_last(void **begin, void **end, ptrdiff_t loc_next); -int cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); - -extern cx_list_class cx_linked_list_class; - -CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size); - -void cxLinkedListDestroy(CxList list); - -size_t cxLinkedListRecalculateSize(CxList list); +/** + * Adds a new node to a linked list. + * + * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. + * + * @param begin a pointer to the begin node pointer (if your list has one) + * @param end a pointer to the end node pointer (if your list has one) + * @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 (negative if your struct does not have one) + * @param new_node a pointer to the node that shall be appended + */ +void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); #ifdef __cplusplus } /* extern "C" */