add missing convenience macros for sorted insert with array reallocator

Sun, 29 Dec 2024 17:45:56 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 29 Dec 2024 17:45:56 +0100
changeset 1066
8610f87a6b14
parent 1065
6eb7b54975ee
child 1067
7799addf475f

add missing convenience macros for sorted insert with array reallocator

src/cx/array_list.h file | annotate | diff | comparison | revisions
--- a/src/cx/array_list.h	Sun Dec 29 16:56:13 2024 +0100
+++ b/src/cx/array_list.h	Sun Dec 29 17:45:56 2024 +0100
@@ -426,6 +426,22 @@
 
 /**
  * Convenience macro for cx_array_add_sorted() with a default
+ * layout and the specified reallocator.
+ *
+ * @param reallocator the array reallocator to use
+ * @param array the name of the array (NOT a pointer to the array)
+ * @param elem the element to add (NOT a pointer, address is automatically taken)
+ * @param cmp_func the compare function for the elements
+ * @return zero on success, non-zero on failure
+ * @see CX_ARRAY_DECLARE()
+ * @see cx_array_simple_add_sorted()
+ */
+#define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \
+    cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \
+        sizeof((array)[0]), &(elem), cmp_func, reallocator)
+
+/**
+ * Convenience macro for cx_array_add_sorted() with a default
  * layout and the default reallocator.
  *
  * @param array the name of the array (NOT a pointer to the array)
@@ -433,10 +449,27 @@
  * @param cmp_func the compare function for the elements
  * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
+ * @see cx_array_simple_add_sorted_a()
  */
 #define cx_array_simple_add_sorted(array, elem, cmp_func) \
-    cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \
-        sizeof((array)[0]), &(elem), cmp_func, cx_array_default_reallocator)
+    cx_array_simple_add_sorted_a(cx_array_default_reallocator, array, elem, cmp_func)
+
+/**
+ * Convenience macro for cx_array_insert_sorted() with a default
+ * layout and the specified reallocator.
+ *
+ * @param reallocator the array reallocator to use
+ * @param array the name of the array (NOT a pointer to the array)
+ * @param src pointer to the source array
+ * @param n number of elements in the source array
+ * @param cmp_func the compare function for the elements
+ * @return zero on success, non-zero on failure
+ * @see CX_ARRAY_DECLARE()
+ * @see cx_array_simple_insert_sorted()
+ */
+#define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \
+    cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \
+        cmp_func, src, sizeof((array)[0]), n, reallocator)
 
 /**
  * Convenience macro for cx_array_insert_sorted() with a default
@@ -448,11 +481,10 @@
  * @param cmp_func the compare function for the elements
  * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
+ * @see cx_array_simple_insert_sorted_a()
  */
 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \
-    cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \
-        cmp_func, src, sizeof((array)[0]), n, cx_array_default_reallocator)
-
+    cx_array_simple_insert_sorted_a(cx_array_default_reallocator, array, src, n, cmp_func)
 
 /**
  * Searches the largest lower bound in a sorted array.

mercurial