1.1 --- a/src/cx/linked_list.h Sun Oct 03 13:07:48 2021 +0200 1.2 +++ b/src/cx/linked_list.h Sun Oct 03 14:06:57 2021 +0200 1.3 @@ -25,6 +25,15 @@ 1.4 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.5 * POSSIBILITY OF SUCH DAMAGE. 1.6 */ 1.7 +/** 1.8 + * \file linked_list.h 1.9 + * \brief Linked list implementation. 1.10 + * \details Also provides several low-level functions for custom linked list implementations. 1.11 + * \author Mike Becker 1.12 + * \author Olaf Wintermann 1.13 + * \version 3.0 1.14 + * \copyright 2-Clause BSD License 1.15 + */ 1.16 1.17 #ifndef UCX_LINKED_LIST_H 1.18 #define UCX_LINKED_LIST_H 1.19 @@ -36,6 +45,13 @@ 1.20 extern "C" { 1.21 #endif 1.22 1.23 +CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size); 1.24 + 1.25 +void cxLinkedListDestroy(CxList list); 1.26 + 1.27 +size_t cxLinkedListRecalculateSize(CxList list); 1.28 + 1.29 + 1.30 /** 1.31 * Finds the node at a certain index. 1.32 * 1.33 @@ -55,17 +71,35 @@ 1.34 */ 1.35 void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index); 1.36 1.37 +/** 1.38 + * Finds the last node in a linked list. 1.39 + * 1.40 + * If a pointer to \p end is provided, the result is just \c *end. 1.41 + * Otherwise, this function starts with the pointer denoted by \c *begin and 1.42 + * traverses the list along a next pointer whose location within the node struct is 1.43 + * denoted by \p loc_next. 1.44 + * 1.45 + * If both \p begin and \p end are \c NULL, an empty list is assumed and this function returns \c NULL. 1.46 + * 1.47 + * @param begin a pointer to the begin node pointer (optional) 1.48 + * @param end a pointer to the end node pointer (optional) 1.49 + * @param loc_next the location of the \c next pointer (only required when \p end is \c NULL) 1.50 + * @return a pointer to the last node or \c NULL if the list is empty 1.51 + */ 1.52 void *cx_linked_list_last(void **begin, void **end, ptrdiff_t loc_next); 1.53 1.54 -int cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.55 - 1.56 -extern cx_list_class cx_linked_list_class; 1.57 - 1.58 -CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size); 1.59 - 1.60 -void cxLinkedListDestroy(CxList list); 1.61 - 1.62 -size_t cxLinkedListRecalculateSize(CxList list); 1.63 +/** 1.64 + * Adds a new node to a linked list. 1.65 + * 1.66 + * \remark One of the pointers \p begin and \p end may be \c NULL, but not both. 1.67 + * 1.68 + * @param begin a pointer to the begin node pointer (if your list has one) 1.69 + * @param end a pointer to the end node pointer (if your list has one) 1.70 + * @param loc_prev the location of a \c prev pointer within your node struct (negative if your struct does not have one) 1.71 + * @param loc_next the location of a \c next pointer within your node struct (negative if your struct does not have one) 1.72 + * @param new_node a pointer to the node that shall be appended 1.73 + */ 1.74 +void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); 1.75 1.76 #ifdef __cplusplus 1.77 } /* extern "C" */