ucx/cx/linked_list.h

changeset 471
063a9f29098c
parent 440
7c4b9cba09ca
--- a/ucx/cx/linked_list.h	Sat Feb 22 18:10:36 2025 +0100
+++ b/ucx/cx/linked_list.h	Sun Feb 23 14:28:47 2025 +0100
@@ -44,17 +44,11 @@
 #endif
 
 /**
- * The maximum item size that uses SBO swap instead of relinking.
- *
- */
-extern const unsigned cx_linked_list_swap_sbo_size;
-
-/**
  * Allocates a linked list for storing elements with @p elem_size bytes each.
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr(), if none is given.
+ * 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.
  *
  * @param allocator the allocator for allocating the list nodes
  * (if @c NULL, a default stdlib allocator will be used)
@@ -67,6 +61,7 @@
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxListFree, 1)
+cx_attr_export
 CxList *cxLinkedListCreate(
         const CxAllocator *allocator,
         cx_compare_func comparator,
@@ -80,9 +75,9 @@
  * to call functions that need a comparator, you must either set one immediately
  * after list creation or use cxLinkedListCreate().
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr().
+ * 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.
  *
  * @param elem_size (@c size_t) the size of each element in bytes
  * @return (@c CxList*) the created list
@@ -109,6 +104,7 @@
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 void *cx_linked_list_at(
         const void *start,
         size_t start_index,
@@ -117,44 +113,26 @@
 );
 
 /**
- * Finds the index of an element within a linked list.
+ * Finds the node containing an element within a linked list.
  *
  * @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
+ * @param found_index an optional pointer where the index of the found node
+ * (given that @p start has index 0) is stored
+ * @return the index of the element, if found - unspecified if not found
  */
-cx_attr_nonnull
-ssize_t cx_linked_list_find(
+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
-);
-
-/**
- * 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
- */
-cx_attr_nonnull
-ssize_t cx_linked_list_find_node(
-        void **result,
-        const void *start,
-        ptrdiff_t loc_advance,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func,
-        const void *elem
+        const void *elem,
+        size_t *found_index
 );
 
 /**
@@ -170,6 +148,7 @@
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 void *cx_linked_list_first(
         const void *node,
         ptrdiff_t loc_prev
@@ -188,6 +167,7 @@
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 void *cx_linked_list_last(
         const void *node,
         ptrdiff_t loc_next
@@ -204,6 +184,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,
@@ -223,6 +204,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,
@@ -244,6 +226,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,
@@ -261,6 +244,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,
@@ -279,6 +263,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,
@@ -301,6 +286,7 @@
  * @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,
@@ -331,6 +317,7 @@
  * @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,
@@ -356,6 +343,7 @@
  * @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,
@@ -385,6 +373,7 @@
  * @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,
@@ -416,6 +405,7 @@
  * @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,
@@ -462,6 +452,8 @@
  * @param loc_next the location of the @c next pointer within the node struct
  * @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
@@ -490,6 +482,7 @@
  * @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,
@@ -514,6 +507,7 @@
  * 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,
@@ -531,6 +525,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,

mercurial