67 * The allocator used for the data. |
67 * The allocator used for the data. |
68 */ |
68 */ |
69 UcxAllocator* allocator; |
69 UcxAllocator* allocator; |
70 } UcxArray; |
70 } UcxArray; |
71 |
71 |
|
72 /** |
|
73 * Sets an element in an arbitrary user defined array. |
|
74 * |
|
75 * If the capacity is insufficient, the array is automatically reallocated and |
|
76 * the possibly new pointer is stored in the <code>array</code> argument. |
|
77 * |
|
78 * On reallocation the capacity of the array is doubled until it is sufficient. |
|
79 * The new capacity is stored back to <code>capacity</code>. |
|
80 * |
|
81 * @param array a pointer to location of the array pointer |
|
82 * @param capacity a pointer to the capacity |
|
83 * @param elmsize the size of each element |
|
84 * @param idx the index of the element to set |
|
85 * @param data the element data |
|
86 * @return zero on success or non-zero on error (errno will be set) |
|
87 */ |
|
88 #define ucx_array_util_set(array, capacity, elmsize, idx, data) \ |
|
89 ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \ |
|
90 elmsize, idx, data) |
|
91 |
|
92 /** |
|
93 * Convenience macro for ucx_array_util_set() which automatically computes |
|
94 * <code>sizeof(data)</code>. |
|
95 * |
|
96 * @param array a pointer to location of the array pointer |
|
97 * @param capacity a pointer to the capacity |
|
98 * @param idx the index of the element to set |
|
99 * @param data the element data |
|
100 * @return zero on success or non-zero on error (errno will be set) |
|
101 * @see ucx_array_util_set() |
|
102 */ |
|
103 #define UCX_ARRAY_UTIL_SET(array, capacity, idx, data) \ |
|
104 ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \ |
|
105 sizeof(data), idx, data) |
|
106 |
|
107 /** |
|
108 * Sets an element in an arbitrary user defined array. |
|
109 * |
|
110 * If the capacity is insufficient, the array is automatically reallocated |
|
111 * using the specified allocator and the possibly new pointer is stored in |
|
112 * the <code>array</code> argument. |
|
113 * |
|
114 * On reallocation the capacity of the array is doubled until it is sufficient. |
|
115 * The new capacity is stored back to <code>capacity</code>. |
|
116 * |
|
117 * @param alloc the allocator that shall be used to reallocate the array |
|
118 * @param array a pointer to location of the array pointer |
|
119 * @param capacity a pointer to the capacity |
|
120 * @param elmsize the size of each element |
|
121 * @param idx the index of the element to set |
|
122 * @param ... the element data |
|
123 * @return zero on success or non-zero on error (errno will be set) |
|
124 */ |
|
125 int ucx_array_util_set_a(UcxAllocator* alloc, void** array, size_t* capacity, |
|
126 size_t elmsize, size_t idx, ...); |
|
127 |
|
128 |
|
129 /** |
|
130 * Convenience macro for ucx_array_util_set_a() which automatically computes |
|
131 * <code>sizeof(data)</code>. |
|
132 * |
|
133 * @param alloc the allocator that shall be used to reallocate the array |
|
134 * @param array a pointer to location of the array pointer |
|
135 * @param capacity a pointer to the capacity |
|
136 * @param idx the index of the element to set |
|
137 * @param data the element data |
|
138 * @return zero on success or non-zero on error (errno will be set) |
|
139 * @see ucx_array_util_set_a() |
|
140 */ |
|
141 #define UCX_ARRAY_UTIL_SET_A(alloc, array, capacity, idx, data) \ |
|
142 ucx_array_util_set_a(alloc, capacity, sizeof(data), idx, data) |
72 |
143 |
73 /** |
144 /** |
74 * Creates a new UCX array with the given capacity and element size. |
145 * Creates a new UCX array with the given capacity and element size. |
75 * @param capacity the initial capacity |
146 * @param capacity the initial capacity |
76 * @param elemsize the element size |
147 * @param elemsize the element size |