diff -r 07b815faa6ac -r f00d03835dd9 src/ucx/cx/kv_list.h --- a/src/ucx/cx/kv_list.h Tue Dec 30 21:44:49 2025 +0100 +++ b/src/ucx/cx/kv_list.h Tue Jan 13 18:09:20 2026 +0100 @@ -40,70 +40,11 @@ #include "list.h" #include "map.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. * * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of * copies of the added elements, and the compare function will be automatically set - * to cx_cmp_ptr() if none is given. - * - * After creating the list, it can also be used as a map after converting the pointer - * to a CxMap pointer with cxKvListAsMap(). - * When you want to use the list interface again, you can also convert the map pointer back - * with cxKvListAsList(). - * - * @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, and the list is not storing pointers, sort and find - * functions will not work) - * @param elem_size the size of each element in bytes - * @return the created list - * @see cxKvListAsMap() - * @see cxKvListAsList() - */ -cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) -CX_EXPORT CxList *cxKvListCreate(const CxAllocator *allocator, - cx_compare_func comparator, size_t elem_size); - -/** - * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. - * - * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of - * copies of the added elements, and the compare function will be automatically set - * to cx_cmp_ptr() if none is given. - * - * This function creates the list with cxKvListCreate() and immediately applies - * cxKvListAsMap(). If you want to use the returned object as a list, you can call - * cxKvListAsList() later. - * - * @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, and the list is not storing pointers, sort and find - * functions will not work) - * @param elem_size the size of each element in bytes - * @return the created list wrapped into the CxMap interface - * @see cxKvListAsMap() - * @see cxKvListAsList() - */ -cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMapFree, 1) -CX_EXPORT CxMap *cxKvListCreateAsMap(const CxAllocator *allocator, - cx_compare_func comparator, size_t elem_size); - -/** - * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. - * - * The list will use cxDefaultAllocator and no comparator function. If you want - * to call functions that need a comparator, you must either set one immediately - * after list creation or use cxKvListCreate(). - * - * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of - * copies of the added elements, and the compare function will be automatically set * to cx_cmp_ptr(). * * After creating the list, it can also be used as a map after converting the pointer @@ -111,34 +52,38 @@ * When you want to use the list interface again, you can also convert the map pointer back * with cxKvListAsList(). * - * @param elem_size (@c size_t) the size of each element in bytes - * @return (@c CxList*) the created list + * @param allocator the allocator for allocating the list nodes + * (if @c NULL, the cxDefaultAllocator will be used) + * @param elem_size the size of each element in bytes + * @return the created list * @see cxKvListAsMap() * @see cxKvListAsList() */ -#define cxKvListCreateSimple(elem_size) cxKvListCreate(NULL, NULL, elem_size) +CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1) +CxList *cxKvListCreate(const CxAllocator *allocator, + size_t elem_size); /** * Allocates a linked list with a lookup-map for storing elements with @p elem_size bytes each. * - * The list will use cxDefaultAllocator and no comparator function. If you want - * to call functions that need a comparator, you must either set one immediately - * after list creation or use cxKvListCreate(). - * * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of * copies of the added elements, and the compare function will be automatically set * to cx_cmp_ptr(). * - * This macro behaves as if the list was created with cxKvListCreateSimple() and - * immediately followed up by cxKvListAsMap(). - * If you want to use the returned object as a list, you can call cxKvListAsList() later. + * This function creates the list with cxKvListCreate() and immediately applies + * cxKvListAsMap(). If you want to use the returned object as a list, you can call + * cxKvListAsList() later. * - * @param elem_size (@c size_t) the size of each element in bytes - * @return (@c CxMap*) the created list wrapped into the CxMap interface + * @param allocator the allocator for allocating the list nodes + * (if @c NULL, the cxDefaultAllocator will be used) + * @param elem_size the size of each element in bytes + * @return the created list wrapped into the CxMap interface * @see cxKvListAsMap() * @see cxKvListAsList() */ -#define cxKvListCreateAsMapSimple(elem_size) cxKvListCreateAsMap(NULL, NULL, elem_size) +CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxMapFree, 1) +CxMap *cxKvListCreateAsMap(const CxAllocator *allocator, + size_t elem_size); /** * Converts a map pointer belonging to a key-value-List back to the original list pointer. @@ -146,17 +91,17 @@ * @param map a map pointer that was returned by a call to cxKvListAsMap() * @return the original list pointer */ -cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull -CX_EXPORT CxList *cxKvListAsList(CxMap *map); +CX_EXTERN CX_NODISCARD CX_NONNULL CX_RETURNS_NONNULL +CxList *cxKvListAsList(CxMap *map); /** * Converts a map pointer belonging to a key-value-List back to the original list pointer. * - * @param list a list created by cxKvListCreate() or cxKvListCreateSimple() + * @param list a list created by cxKvListCreate() * @return a map pointer that lets you use the list as if it was a map */ -cx_attr_nodiscard cx_attr_nonnull cx_attr_returns_nonnull -CX_EXPORT CxMap *cxKvListAsMap(CxList *list); +CX_EXTERN CX_NODISCARD CX_NONNULL CX_RETURNS_NONNULL +CxMap *cxKvListAsMap(CxList *list); /** * Sets or updates the key of a list item. @@ -171,8 +116,8 @@ * @retval non-zero memory allocation failure or the index is out of bounds * @see cxKvListSetKey() */ -cx_attr_nonnull -CX_EXPORT int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); +CX_EXTERN CX_NONNULL +int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key); /** * Inserts an item into the list at the specified index and associates it with the specified key. @@ -185,8 +130,8 @@ * @retval non-zero memory allocation failure or the index is out of bounds * @see cxKvListInsert() */ -cx_attr_nonnull -CX_EXPORT int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); +CX_EXTERN CX_NONNULL +int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); /** * Sets or updates the key of a list item. @@ -216,7 +161,6 @@ */ #define cxKvListInsert(list, index, key, value) cx_kv_list_insert(list, index, CX_HASH_KEY(key), value) - /** * Removes the key of a list item. * @@ -229,8 +173,8 @@ * @retval zero success * @retval non-zero the index is out of bounds */ -cx_attr_nonnull -CX_EXPORT int cxKvListRemoveKey(CxList *list, size_t index); +CX_EXTERN CX_NONNULL +int cxKvListRemoveKey(CxList *list, size_t index); /** * Returns the key of a list item. @@ -239,8 +183,8 @@ * @param index the index of the element in the list * @return a pointer to the key or @c NULL when the index is out of bounds or the item does not have a key */ -cx_attr_nonnull -CX_EXPORT const CxHashKey *cxKvListGetKey(CxList *list, size_t index); +CX_EXTERN CX_NONNULL CX_NODISCARD +const CxHashKey *cxKvListGetKey(CxList *list, size_t index); /** * Adds an item into the list and associates it with the specified key. @@ -253,8 +197,4 @@ */ #define cxKvListAdd(list, key, value) cxKvListInsert(list, (list)->collection.size, key, value) -#ifdef __cplusplus -} // extern "C" -#endif - #endif // UCX_KV_LIST_H