diff -r 7d176764756d -r 087cc9216f28 ucx/cx/linked_list.h --- a/ucx/cx/linked_list.h Sun Feb 11 15:44:33 2024 +0100 +++ b/ucx/cx/linked_list.h Sun Feb 11 22:06:23 2024 +0100 @@ -31,7 +31,6 @@ * \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 */ @@ -46,21 +45,22 @@ #endif /** - * Set this flag to true, if you want to disable the use of SBO for - * linked list swap operations. + * The maximum item size that uses SBO swap instead of relinking. */ -extern bool CX_DISABLE_LINKED_LIST_SWAP_SBO; +extern unsigned cx_linked_list_swap_sbo_size; /** * Allocates a linked list for storing elements with \p item_size bytes each. * * If \p item_size is CX_STORE_POINTERS, the created list will be created as if - * cxListStorePointers() was called immediately after creation. + * cxListStorePointers() was called immediately after creation and the compare + * function will be automatically set to cx_cmp_ptr(), if none is given. * * @param allocator the allocator for allocating the list nodes * (if \c NULL the cxDefaultAllocator will be used) * @param comparator the comparator for the elements - * (if \c NULL sort and find functions will not work) + * (if \c NULL, and the list is not storing pointers, sort and find + * functions will not work) * @param item_size the size of each element in bytes * @return the created list */ @@ -78,7 +78,8 @@ * after list creation or use cxLinkedListCreate(). * * If \p item_size is CX_STORE_POINTERS, the created list will be created as if - * cxListStorePointers() was called immediately after creation. + * cxListStorePointers() was called immediately after creation and the compare + * function will be automatically set to cx_cmp_ptr(). * * @param item_size the size of each element in bytes * @return the created list @@ -129,6 +130,27 @@ ) __attribute__((__nonnull__)); /** + * Finds the node containing an element within a linked list. + * + * @param result a pointer to the memory where the node pointer (or \c NULL if the element + * could not be found) shall be stored to + * @param start a pointer to the start node + * @param loc_advance the location of the pointer to advance + * @param loc_data the location of the \c data pointer within your node struct + * @param cmp_func a compare function to compare \p elem against the node data + * @param elem a pointer to the element to find + * @return the index of the element or a negative value if it could not be found + */ +ssize_t cx_linked_list_find_node( + void **result, + void const *start, + ptrdiff_t loc_advance, + ptrdiff_t loc_data, + cx_compare_func cmp_func, + void const *elem +) __attribute__((__nonnull__)); + +/** * Finds the first node in a linked list. * * The function starts with the pointer denoted by \p node and traverses the list