src/cx/linked_list.h

changeset 1426
3a89b31f0724
parent 1424
563033aa998c
--- a/src/cx/linked_list.h	Wed Oct 15 22:45:21 2025 +0200
+++ b/src/cx/linked_list.h	Thu Oct 16 19:57:47 2025 +0200
@@ -90,15 +90,9 @@
  * @param elem_size the size of each element in bytes
  * @return the created list
  */
-cx_attr_nodiscard
-cx_attr_malloc
-cx_attr_dealloc(cxListFree, 1)
-cx_attr_export
-CxList *cxLinkedListCreate(
-        const CxAllocator *allocator,
-        cx_compare_func comparator,
-        size_t elem_size
-);
+cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1)
+CX_EXPORT CxList *cxLinkedListCreate(const CxAllocator *allocator,
+        cx_compare_func comparator, size_t elem_size);
 
 /**
  * Allocates a linked list for storing elements with @p elem_size bytes each.
@@ -115,7 +109,7 @@
  * @return (@c CxList*) the created list
  */
 #define cxLinkedListCreateSimple(elem_size) \
-    cxLinkedListCreate(NULL, NULL, elem_size)
+        cxLinkedListCreate(NULL, NULL, elem_size)
 
 /**
  * Finds the node at a certain index.
@@ -134,15 +128,9 @@
  * @param index the search index
  * @return the node found at the specified index
  */
-cx_attr_nonnull
-cx_attr_nodiscard
-cx_attr_export
-void *cx_linked_list_at(
-        const void *start,
-        size_t start_index,
-        ptrdiff_t loc_advance,
-        size_t index
-);
+cx_attr_nonnull cx_attr_nodiscard
+CX_EXPORT void *cx_linked_list_at(const void *start,size_t start_index,
+        ptrdiff_t loc_advance, size_t index);
 
 /**
  * Finds the node containing an element within a linked list.
@@ -157,15 +145,9 @@
  * @return a pointer to the found node or @c NULL if no matching node was found
  */
 cx_attr_nonnull_arg(1, 4, 5)
-cx_attr_export
-void *cx_linked_list_find(
-        const void *start,
-        ptrdiff_t loc_advance,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func,
-        const void *elem,
-        size_t *found_index
-);
+CX_EXPORT void *cx_linked_list_find(const void *start, ptrdiff_t loc_advance,
+        ptrdiff_t loc_data, cx_compare_func cmp_func, const void *elem,
+        size_t *found_index);
 
 /**
  * Finds the first node in a linked list.
@@ -178,13 +160,8 @@
  * @param loc_prev the location of the @c prev pointer
  * @return a pointer to the first node
  */
-cx_attr_nonnull
-cx_attr_returns_nonnull
-cx_attr_export
-void *cx_linked_list_first(
-        const void *node,
-        ptrdiff_t loc_prev
-);
+cx_attr_nonnull cx_attr_returns_nonnull
+CX_EXPORT void *cx_linked_list_first(const void *node, ptrdiff_t loc_prev);
 
 /**
  * Finds the last node in a linked list.
@@ -197,13 +174,8 @@
  * @param loc_next the location of the @c next pointer
  * @return a pointer to the last node
  */
-cx_attr_nonnull
-cx_attr_returns_nonnull
-cx_attr_export
-void *cx_linked_list_last(
-        const void *node,
-        ptrdiff_t loc_next
-);
+cx_attr_nonnull cx_attr_returns_nonnull
+CX_EXPORT void *cx_linked_list_last(const void *node, ptrdiff_t loc_next);
 
 /**
  * Finds the predecessor of a node in case it is not linked.
@@ -216,12 +188,7 @@
  * @return the node or @c NULL if @p node has no predecessor
  */
 cx_attr_nonnull
-cx_attr_export
-void *cx_linked_list_prev(
-        const void *begin,
-        ptrdiff_t loc_next,
-        const void *node
-);
+CX_EXPORT void *cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node);
 
 /**
  * Adds a new node to a linked list.
@@ -236,14 +203,7 @@
  * @param new_node a pointer to the node that shall be appended
  */
 cx_attr_nonnull_arg(5)
-cx_attr_export
-void cx_linked_list_add(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *new_node
-);
+CX_EXPORT void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
 
 /**
  * Prepends a new node to a linked list.
@@ -258,14 +218,7 @@
  * @param new_node a pointer to the node that shall be prepended
  */
 cx_attr_nonnull_arg(5)
-cx_attr_export
-void cx_linked_list_prepend(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *new_node
-);
+CX_EXPORT void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node);
 
 /**
  * Links two nodes.
@@ -276,13 +229,7 @@
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull
-cx_attr_export
-void cx_linked_list_link(
-        void *left,
-        void *right,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next
-);
+CX_EXPORT void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next);
 
 /**
  * Unlinks two nodes.
@@ -295,13 +242,7 @@
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull
-cx_attr_export
-void cx_linked_list_unlink(
-        void *left,
-        void *right,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next
-);
+CX_EXPORT void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next);
 
 /**
  * Inserts a new node after a given node of a linked list.
@@ -318,15 +259,8 @@
  * @param new_node a pointer to the node that shall be inserted
  */
 cx_attr_nonnull_arg(6)
-cx_attr_export
-void cx_linked_list_insert(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *node,
-        void *new_node
-);
+CX_EXPORT void cx_linked_list_insert(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node);
 
 /**
  * Inserts a chain of nodes after a given node of a linked list.
@@ -349,16 +283,8 @@
  * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined)
  */
 cx_attr_nonnull_arg(6)
-cx_attr_export
-void cx_linked_list_insert_chain(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *node,
-        void *insert_begin,
-        void *insert_end
-);
+CX_EXPORT void cx_linked_list_insert_chain(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end);
 
 /**
  * Inserts a node into a sorted linked list.
@@ -375,15 +301,8 @@
  * @param cmp_func a compare function that will receive the node pointers
  */
 cx_attr_nonnull_arg(1, 5, 6)
-cx_attr_export
-void cx_linked_list_insert_sorted(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *new_node,
-        cx_compare_func cmp_func
-);
+CX_EXPORT void cx_linked_list_insert_sorted(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func);
 
 /**
  * Inserts a chain of nodes into a sorted linked list.
@@ -405,15 +324,8 @@
  * @param cmp_func a compare function that will receive the node pointers
  */
 cx_attr_nonnull_arg(1, 5, 6)
-cx_attr_export
-void cx_linked_list_insert_sorted_chain(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *insert_begin,
-        cx_compare_func cmp_func
-);
+CX_EXPORT void cx_linked_list_insert_sorted_chain(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func);
 
 /**
  * Inserts a node into a sorted linked list if no other node with the same value already exists.
@@ -432,15 +344,8 @@
  * @retval non-zero when a node with the same value already exists
  */
 cx_attr_nonnull_arg(1, 5, 6)
-cx_attr_export
-int cx_linked_list_insert_unique(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *new_node,
-        cx_compare_func cmp_func
-);
+CX_EXPORT int cx_linked_list_insert_unique(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func);
 
 /**
  * Inserts a chain of nodes into a sorted linked list, avoiding duplicates.
@@ -460,17 +365,9 @@
  * @param cmp_func a compare function that will receive the node pointers
  * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates)
  */
-cx_attr_nonnull_arg(1, 5, 6)
-cx_attr_nodiscard
-cx_attr_export
-void *cx_linked_list_insert_unique_chain(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *insert_begin,
-        cx_compare_func cmp_func
-);
+cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard
+CX_EXPORT void *cx_linked_list_insert_unique_chain(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func);
 
 /**
  * Removes a chain of nodes from the linked list.
@@ -494,15 +391,8 @@
  * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes)
  */
 cx_attr_nonnull_arg(5)
-cx_attr_export
-size_t cx_linked_list_remove_chain(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        void *node,
-        size_t num
-);
+CX_EXPORT 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.
@@ -524,15 +414,8 @@
  * @param node the node to remove
  */
 cx_attr_nonnull_arg(5)
-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);
-}
+CX_EXPORT void cx_linked_list_remove(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node);
 
 /**
  * Determines the size of a linked list starting with @p node.
@@ -542,11 +425,7 @@
  * @return the size of the list or zero if @p node is @c NULL
  */
 cx_attr_nodiscard
-cx_attr_export
-size_t cx_linked_list_size(
-        const void *node,
-        ptrdiff_t loc_next
-);
+CX_EXPORT size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next);
 
 /**
  * Sorts a linked list based on a comparison function.
@@ -571,15 +450,8 @@
  * @param cmp_func the compare function defining the sort order
  */
 cx_attr_nonnull_arg(1, 6)
-cx_attr_export
-void cx_linked_list_sort(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func
-);
+CX_EXPORT void cx_linked_list_sort(void **begin, void **end,
+        ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func);
 
 
 /**
@@ -596,14 +468,8 @@
  * right list, positive if the left list is larger than the right list, zero if both lists are equal.
  */
 cx_attr_nonnull_arg(5)
-cx_attr_export
-int cx_linked_list_compare(
-        const void *begin_left,
-        const void *begin_right,
-        ptrdiff_t loc_advance,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func
-);
+CX_EXPORT int cx_linked_list_compare(const void *begin_left, const void *begin_right,
+        ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func);
 
 /**
  * Reverses the order of the nodes in a linked list.
@@ -614,13 +480,7 @@
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull_arg(1)
-cx_attr_export
-void cx_linked_list_reverse(
-        void **begin,
-        void **end,
-        ptrdiff_t loc_prev,
-        ptrdiff_t loc_next
-);
+CX_EXPORT void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next);
 
 #ifdef __cplusplus
 } // extern "C"

mercurial