diff -r 7fd13b9f8f60 -r d315a068235a src/ucx/array.h
--- a/src/ucx/array.h Sat Aug 10 11:12:49 2019 +0200
+++ b/src/ucx/array.h Tue Sep 24 20:16:00 2019 +0200
@@ -69,6 +69,77 @@
UcxAllocator* allocator;
} UcxArray;
+/**
+ * Sets an element in an arbitrary user defined array.
+ *
+ * If the capacity is insufficient, the array is automatically reallocated and
+ * the possibly new pointer is stored in the array
argument.
+ *
+ * On reallocation the capacity of the array is doubled until it is sufficient.
+ * The new capacity is stored back to capacity
.
+ *
+ * @param array a pointer to location of the array pointer
+ * @param capacity a pointer to the capacity
+ * @param elmsize the size of each element
+ * @param idx the index of the element to set
+ * @param data the element data
+ * @return zero on success or non-zero on error (errno will be set)
+ */
+#define ucx_array_util_set(array, capacity, elmsize, idx, data) \
+ ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \
+ elmsize, idx, data)
+
+/**
+ * Convenience macro for ucx_array_util_set() which automatically computes
+ * sizeof(data)
.
+ *
+ * @param array a pointer to location of the array pointer
+ * @param capacity a pointer to the capacity
+ * @param idx the index of the element to set
+ * @param data the element data
+ * @return zero on success or non-zero on error (errno will be set)
+ * @see ucx_array_util_set()
+ */
+#define UCX_ARRAY_UTIL_SET(array, capacity, idx, data) \
+ ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \
+ sizeof(data), idx, data)
+
+/**
+ * Sets an element in an arbitrary user defined array.
+ *
+ * If the capacity is insufficient, the array is automatically reallocated
+ * using the specified allocator and the possibly new pointer is stored in
+ * the array
argument.
+ *
+ * On reallocation the capacity of the array is doubled until it is sufficient.
+ * The new capacity is stored back to capacity
.
+ *
+ * @param alloc the allocator that shall be used to reallocate the array
+ * @param array a pointer to location of the array pointer
+ * @param capacity a pointer to the capacity
+ * @param elmsize the size of each element
+ * @param idx the index of the element to set
+ * @param ... the element data
+ * @return zero on success or non-zero on error (errno will be set)
+ */
+int ucx_array_util_set_a(UcxAllocator* alloc, void** array, size_t* capacity,
+ size_t elmsize, size_t idx, ...);
+
+
+/**
+ * Convenience macro for ucx_array_util_set_a() which automatically computes
+ * sizeof(data)
.
+ *
+ * @param alloc the allocator that shall be used to reallocate the array
+ * @param array a pointer to location of the array pointer
+ * @param capacity a pointer to the capacity
+ * @param idx the index of the element to set
+ * @param data the element data
+ * @return zero on success or non-zero on error (errno will be set)
+ * @see ucx_array_util_set_a()
+ */
+#define UCX_ARRAY_UTIL_SET_A(alloc, array, capacity, idx, data) \
+ ucx_array_util_set_a(alloc, capacity, sizeof(data), idx, data)
/**
* Creates a new UCX array with the given capacity and element size.