| 116 */ |
155 */ |
| 117 size_t int2; |
156 size_t int2; |
| 118 }; |
157 }; |
| 119 |
158 |
| 120 /** |
159 /** |
| |
160 * Typedef for the array reallocator struct. |
| |
161 */ |
| |
162 typedef struct cx_array_reallocator_s CxArrayReallocator; |
| |
163 |
| |
164 /** |
| 121 * A default stdlib-based array reallocator. |
165 * A default stdlib-based array reallocator. |
| 122 */ |
166 */ |
| 123 extern struct cx_array_reallocator_s *cx_array_default_reallocator; |
167 extern struct cx_array_reallocator_s *cx_array_default_reallocator; |
| 124 |
168 |
| 125 /** |
169 /** |
| 126 * Return codes for array functions. |
170 * Creates a new array reallocator. |
| 127 */ |
171 * |
| 128 enum cx_array_result { |
172 * When \p allocator is \c NULL, the stdlib default allocator will be used. |
| 129 CX_ARRAY_SUCCESS, |
173 * |
| 130 CX_ARRAY_REALLOC_NOT_SUPPORTED, |
174 * When \p stackmem is not \c NULL, the reallocator is supposed to be used |
| 131 CX_ARRAY_REALLOC_FAILED, |
175 * \em only for the specific array that is initially located at \p stackmem. |
| 132 }; |
176 * When reallocation is needed, the reallocator checks, if the array is |
| |
177 * still located at \p stackmem and copies the contents to the heap. |
| |
178 * |
| |
179 * @param allocator the allocator this reallocator shall be based on |
| |
180 * @param stackmem the address of the array when the array is initially located |
| |
181 * on the stack |
| |
182 * @return an array reallocator |
| |
183 */ |
| |
184 struct cx_array_reallocator_s cx_array_reallocator( |
| |
185 const struct cx_allocator_s *allocator, |
| |
186 const void *stackmem |
| |
187 ); |
| |
188 |
| |
189 /** |
| |
190 * Reserves memory for additional elements. |
| |
191 * |
| |
192 * This function checks if the \p capacity of the array is sufficient to hold |
| |
193 * at least \p size plus \p elem_count elements. If not, a reallocation is |
| |
194 * performed with the specified \p reallocator. |
| |
195 * |
| |
196 * This function can be useful to replace subsequent calls to cx_array_copy() |
| |
197 * with one single cx_array_reserve() and then - after guaranteeing a |
| |
198 * sufficient capacity - use simple memmove() or memcpy(). |
| |
199 * |
| |
200 * The \p width refers to the size and capacity. Both must have the same width. |
| |
201 * Supported are 0, 8, 16, and 32, as well as 64 if running on a 64 bit |
| |
202 * architecture. If set to zero, the native word width is used. |
| |
203 * |
| |
204 * @param array a pointer to the target array |
| |
205 * @param size a pointer to the size of the array |
| |
206 * @param capacity a pointer to the capacity of the array |
| |
207 * @param width the width in bytes for the \p size and \p capacity or zero for default |
| |
208 * @param elem_size the size of one element |
| |
209 * @param elem_count the number of expected additional elements |
| |
210 * @param reallocator the array reallocator to use |
| |
211 * @return zero on success, non-zero on failure |
| |
212 */ |
| |
213 cx_attr_nonnull |
| |
214 int cx_array_reserve( |
| |
215 void **array, |
| |
216 void *size, |
| |
217 void *capacity, |
| |
218 unsigned width, |
| |
219 size_t elem_size, |
| |
220 size_t elem_count, |
| |
221 struct cx_array_reallocator_s *reallocator |
| |
222 ); |
| 133 |
223 |
| 134 /** |
224 /** |
| 135 * Copies elements from one array to another. |
225 * Copies elements from one array to another. |
| 136 * |
226 * |
| 137 * The elements are copied to the \p target array at the specified \p index, |
227 * The elements are copied to the \p target array at the specified \p index, |
| 138 * overwriting possible elements. The \p index does not need to be in range of |
228 * overwriting possible elements. The \p index does not need to be in range of |
| 139 * the current array \p size. If the new index plus the number of elements added |
229 * the current array \p size. If the new index plus the number of elements added |
| 140 * would extend the array's size, and \p capacity is not \c NULL, the remaining |
230 * would extend the array's size, the remaining \p capacity is used. |
| 141 * capacity is used. |
231 * |
| 142 * |
232 * If the \p capacity is also insufficient to hold the new data, a reallocation |
| 143 * If the capacity is insufficient to hold the new data, a reallocation |
233 * attempt is made with the specified \p reallocator. |
| 144 * attempt is made, unless the \p reallocator is set to \c NULL, in which case |
234 * |
| 145 * this function ultimately returns a failure. |
235 * The \p width refers to the size and capacity. Both must have the same width. |
| |
236 * Supported are 0, 8, 16, and 32, as well as 64 if running on a 64 bit |
| |
237 * architecture. If set to zero, the native word width is used. |
| 146 * |
238 * |
| 147 * @param target a pointer to the target array |
239 * @param target a pointer to the target array |
| 148 * @param size a pointer to the size of the target array |
240 * @param size a pointer to the size of the target array |
| 149 * @param capacity a pointer to the target array's capacity - |
241 * @param capacity a pointer to the capacity of the target array |
| 150 * \c NULL if only the size shall be used to bound the array |
242 * @param width the width in bytes for the \p size and \p capacity or zero for default |
| 151 * @param index the index where the copied elements shall be placed |
243 * @param index the index where the copied elements shall be placed |
| 152 * @param src the source array |
244 * @param src the source array |
| 153 * @param elem_size the size of one element |
245 * @param elem_size the size of one element |
| 154 * @param elem_count the number of elements to copy |
246 * @param elem_count the number of elements to copy |
| 155 * @param reallocator the array reallocator to use, or \c NULL |
247 * @param reallocator the array reallocator to use |
| 156 * if reallocation shall not happen |
248 * @return zero on success, non-zero on failure |
| 157 * @return zero on success, non-zero error code on failure |
249 */ |
| 158 */ |
250 cx_attr_nonnull |
| 159 enum cx_array_result cx_array_copy( |
251 int cx_array_copy( |
| |
252 void **target, |
| |
253 void *size, |
| |
254 void *capacity, |
| |
255 unsigned width, |
| |
256 size_t index, |
| |
257 const void *src, |
| |
258 size_t elem_size, |
| |
259 size_t elem_count, |
| |
260 struct cx_array_reallocator_s *reallocator |
| |
261 ); |
| |
262 |
| |
263 /** |
| |
264 * Convenience macro that uses cx_array_copy() with a default layout and |
| |
265 * the specified reallocator. |
| |
266 * |
| |
267 * @param reallocator the array reallocator to use |
| |
268 * @param array the name of the array (NOT a pointer to the array) |
| |
269 * @param index the index where the copied elements shall be placed |
| |
270 * @param src the source array |
| |
271 * @param count the number of elements to copy |
| |
272 * @return zero on success, non-zero on failure |
| |
273 * @see CX_ARRAY_DECLARE() |
| |
274 * @see cx_array_simple_copy() |
| |
275 */ |
| |
276 #define cx_array_simple_copy_a(reallocator, array, index, src, count) \ |
| |
277 cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \ |
| |
278 8*sizeof(array##_size), index, src, sizeof((array)[0]), count, \ |
| |
279 reallocator) |
| |
280 |
| |
281 /** |
| |
282 * Convenience macro that uses cx_array_copy() with a default layout and |
| |
283 * the default reallocator. |
| |
284 * |
| |
285 * @param array the name of the array (NOT a pointer to the array) |
| |
286 * @param index the index where the copied elements shall be placed |
| |
287 * @param src the source array |
| |
288 * @param count the number of elements to copy |
| |
289 * @return zero on success, non-zero on failure |
| |
290 * @see CX_ARRAY_DECLARE() |
| |
291 * @see cx_array_simple_copy_a() |
| |
292 */ |
| |
293 #define cx_array_simple_copy(array, index, src, count) \ |
| |
294 cx_array_simple_copy_a(cx_array_default_reallocator, \ |
| |
295 array, index, src, count) |
| |
296 |
| |
297 /** |
| |
298 * Convenience macro that uses cx_array_reserve() with a default layout and |
| |
299 * the specified reallocator. |
| |
300 * |
| |
301 * @param reallocator the array reallocator to use |
| |
302 * @param array the name of the array (NOT a pointer to the array) |
| |
303 * @param count the number of expected additional elements |
| |
304 * @return zero on success, non-zero on failure |
| |
305 * @see CX_ARRAY_DECLARE() |
| |
306 * @see cx_array_simple_reserve() |
| |
307 */ |
| |
308 #define cx_array_simple_reserve_a(reallocator, array, count) \ |
| |
309 cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \ |
| |
310 8*sizeof(array##_size), sizeof((array)[0]), count, \ |
| |
311 reallocator) |
| |
312 |
| |
313 /** |
| |
314 * Convenience macro that uses cx_array_reserve() with a default layout and |
| |
315 * the default reallocator. |
| |
316 * |
| |
317 * @param array the name of the array (NOT a pointer to the array) |
| |
318 * @param count the number of expected additional elements |
| |
319 * @return zero on success, non-zero on failure |
| |
320 * @see CX_ARRAY_DECLARE() |
| |
321 * @see cx_array_simple_reserve_a() |
| |
322 */ |
| |
323 #define cx_array_simple_reserve(array, count) \ |
| |
324 cx_array_simple_reserve_a(cx_array_default_reallocator, \ |
| |
325 array, count) |
| |
326 |
| |
327 /** |
| |
328 * Adds an element to an array with the possibility of allocating more space. |
| |
329 * |
| |
330 * The element \p elem is added to the end of the \p target array which contains |
| |
331 * \p size elements, already. The \p capacity must point to a variable denoting |
| |
332 * the current maximum number of elements the array can hold. |
| |
333 * |
| |
334 * If the capacity is insufficient to hold the new element, an attempt to |
| |
335 * increase the \p capacity is made and the new capacity is written back. |
| |
336 * |
| |
337 * @param target a pointer to the target array |
| |
338 * @param size a pointer to the size of the target array |
| |
339 * @param capacity a pointer to the capacity of the target array |
| |
340 * @param elem_size the size of one element |
| |
341 * @param elem a pointer to the element to add |
| |
342 * @param reallocator the array reallocator to use |
| |
343 * @return zero on success, non-zero on failure |
| |
344 */ |
| |
345 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \ |
| |
346 cx_array_copy((void**)(target), size, capacity, 8*sizeof(*(size)), \ |
| |
347 *(size), elem, elem_size, 1, reallocator) |
| |
348 |
| |
349 /** |
| |
350 * Convenience macro that uses cx_array_add() with a default layout and |
| |
351 * the specified reallocator. |
| |
352 * |
| |
353 * @param reallocator the array reallocator to use |
| |
354 * @param array the name of the array (NOT a pointer to the array) |
| |
355 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| |
356 * @return zero on success, non-zero on failure |
| |
357 * @see CX_ARRAY_DECLARE() |
| |
358 * @see cx_array_simple_add() |
| |
359 */ |
| |
360 #define cx_array_simple_add_a(reallocator, array, elem) \ |
| |
361 cx_array_simple_copy_a(reallocator, array, array##_size, &(elem), 1) |
| |
362 |
| |
363 /** |
| |
364 * Convenience macro that uses cx_array_add() with a default layout and |
| |
365 * the default reallocator. |
| |
366 * |
| |
367 * @param array the name of the array (NOT a pointer to the array) |
| |
368 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| |
369 * @return zero on success, non-zero on failure |
| |
370 * @see CX_ARRAY_DECLARE() |
| |
371 * @see cx_array_simple_add_a() |
| |
372 */ |
| |
373 #define cx_array_simple_add(array, elem) \ |
| |
374 cx_array_simple_add_a(cx_array_default_reallocator, array, elem) |
| |
375 |
| |
376 /** |
| |
377 * Inserts a sorted array into another sorted array. |
| |
378 * |
| |
379 * If either the target or the source array is not already sorted with respect |
| |
380 * to the specified \p cmp_func, the behavior is undefined. |
| |
381 * |
| |
382 * If the capacity is insufficient to hold the new data, a reallocation |
| |
383 * attempt is made. |
| |
384 * |
| |
385 * @param target a pointer to the target array |
| |
386 * @param size a pointer to the size of the target array |
| |
387 * @param capacity a pointer to the capacity of the target array |
| |
388 * @param cmp_func the compare function for the elements |
| |
389 * @param src the source array |
| |
390 * @param elem_size the size of one element |
| |
391 * @param elem_count the number of elements to insert |
| |
392 * @param reallocator the array reallocator to use |
| |
393 * @return zero on success, non-zero on failure |
| |
394 */ |
| |
395 cx_attr_nonnull |
| |
396 int cx_array_insert_sorted( |
| 160 void **target, |
397 void **target, |
| 161 size_t *size, |
398 size_t *size, |
| 162 size_t *capacity, |
399 size_t *capacity, |
| 163 size_t index, |
400 cx_compare_func cmp_func, |
| 164 void const *src, |
401 const void *src, |
| 165 size_t elem_size, |
402 size_t elem_size, |
| 166 size_t elem_count, |
403 size_t elem_count, |
| 167 struct cx_array_reallocator_s *reallocator |
404 struct cx_array_reallocator_s *reallocator |
| 168 ) __attribute__((__nonnull__(1, 2, 5))); |
405 ); |
| 169 |
406 |
| 170 /** |
407 /** |
| 171 * Convenience macro that uses cx_array_copy() with a default layout and the default reallocator. |
408 * Inserts an element into a sorted array. |
| 172 * |
409 * |
| 173 * @param array the name of the array (NOT a pointer to the array) |
410 * If the target array is not already sorted with respect |
| 174 * @param index the index where the copied elements shall be placed |
411 * to the specified \p cmp_func, the behavior is undefined. |
| 175 * @param src the source array |
412 * |
| 176 * @param count the number of elements to copy |
413 * If the capacity is insufficient to hold the new data, a reallocation |
| 177 */ |
414 * attempt is made. |
| 178 #define cx_array_simple_copy(array, index, src, count) \ |
|
| 179 cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \ |
|
| 180 index, src, sizeof((array)[0]), count, cx_array_default_reallocator) |
|
| 181 |
|
| 182 /** |
|
| 183 * Adds an element to an array with the possibility of allocating more space. |
|
| 184 * |
|
| 185 * The element \p elem is added to the end of the \p target array which containing |
|
| 186 * \p size elements, already. The \p capacity must not be \c NULL and point a |
|
| 187 * variable holding the current maximum number of elements the array can hold. |
|
| 188 * |
|
| 189 * If the capacity is insufficient to hold the new element, and the optional |
|
| 190 * \p reallocator is not \c NULL, an attempt increase the \p capacity is made |
|
| 191 * and the new capacity is written back. |
|
| 192 * |
415 * |
| 193 * @param target a pointer to the target array |
416 * @param target a pointer to the target array |
| 194 * @param size a pointer to the size of the target array |
417 * @param size a pointer to the size of the target array |
| 195 * @param capacity a pointer to the target array's capacity - must not be \c NULL |
418 * @param capacity a pointer to the capacity of the target array |
| 196 * @param elem_size the size of one element |
419 * @param elem_size the size of one element |
| 197 * @param elem a pointer to the element to add |
420 * @param elem a pointer to the element to add |
| 198 * @param reallocator the array reallocator to use, or \c NULL if reallocation shall not happen |
421 * @param reallocator the array reallocator to use |
| 199 * @return zero on success, non-zero error code on failure |
422 * @return zero on success, non-zero on failure |
| 200 */ |
423 */ |
| 201 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \ |
424 #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \ |
| 202 cx_array_copy((void**)(target), size, capacity, *(size), elem, elem_size, 1, reallocator) |
425 cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator) |
| 203 |
426 |
| 204 /** |
427 /** |
| 205 * Convenience macro that uses cx_array_add() with a default layout and the default reallocator. |
428 * Convenience macro for cx_array_add_sorted() with a default |
| 206 * |
429 * layout and the specified reallocator. |
| |
430 * |
| |
431 * @param reallocator the array reallocator to use |
| 207 * @param array the name of the array (NOT a pointer to the array) |
432 * @param array the name of the array (NOT a pointer to the array) |
| 208 * @param elem the element to add (NOT a pointer, address is automatically taken) |
433 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| 209 */ |
434 * @param cmp_func the compare function for the elements |
| 210 #define cx_array_simple_add(array, elem) \ |
435 * @return zero on success, non-zero on failure |
| 211 cx_array_simple_copy(array, array##_size, &(elem), 1) |
436 * @see CX_ARRAY_DECLARE() |
| |
437 * @see cx_array_simple_add_sorted() |
| |
438 */ |
| |
439 #define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \ |
| |
440 cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \ |
| |
441 sizeof((array)[0]), &(elem), cmp_func, reallocator) |
| |
442 |
| |
443 /** |
| |
444 * Convenience macro for cx_array_add_sorted() with a default |
| |
445 * layout and the default reallocator. |
| |
446 * |
| |
447 * @param array the name of the array (NOT a pointer to the array) |
| |
448 * @param elem the element to add (NOT a pointer, address is automatically taken) |
| |
449 * @param cmp_func the compare function for the elements |
| |
450 * @return zero on success, non-zero on failure |
| |
451 * @see CX_ARRAY_DECLARE() |
| |
452 * @see cx_array_simple_add_sorted_a() |
| |
453 */ |
| |
454 #define cx_array_simple_add_sorted(array, elem, cmp_func) \ |
| |
455 cx_array_simple_add_sorted_a(cx_array_default_reallocator, array, elem, cmp_func) |
| |
456 |
| |
457 /** |
| |
458 * Convenience macro for cx_array_insert_sorted() with a default |
| |
459 * layout and the specified reallocator. |
| |
460 * |
| |
461 * @param reallocator the array reallocator to use |
| |
462 * @param array the name of the array (NOT a pointer to the array) |
| |
463 * @param src pointer to the source array |
| |
464 * @param n number of elements in the source array |
| |
465 * @param cmp_func the compare function for the elements |
| |
466 * @return zero on success, non-zero on failure |
| |
467 * @see CX_ARRAY_DECLARE() |
| |
468 * @see cx_array_simple_insert_sorted() |
| |
469 */ |
| |
470 #define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \ |
| |
471 cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \ |
| |
472 cmp_func, src, sizeof((array)[0]), n, reallocator) |
| |
473 |
| |
474 /** |
| |
475 * Convenience macro for cx_array_insert_sorted() with a default |
| |
476 * layout and the default reallocator. |
| |
477 * |
| |
478 * @param array the name of the array (NOT a pointer to the array) |
| |
479 * @param src pointer to the source array |
| |
480 * @param n number of elements in the source array |
| |
481 * @param cmp_func the compare function for the elements |
| |
482 * @return zero on success, non-zero on failure |
| |
483 * @see CX_ARRAY_DECLARE() |
| |
484 * @see cx_array_simple_insert_sorted_a() |
| |
485 */ |
| |
486 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ |
| |
487 cx_array_simple_insert_sorted_a(cx_array_default_reallocator, array, src, n, cmp_func) |
| |
488 |
| |
489 /** |
| |
490 * Searches the largest lower bound in a sorted array. |
| |
491 * |
| |
492 * In other words, this function returns the index of the largest element |
| |
493 * in \p arr that is less or equal to \p elem with respect to \p cmp_func. |
| |
494 * When no such element exists, \p size is returned. |
| |
495 * |
| |
496 * If \p elem is contained in the array, this is identical to |
| |
497 * #cx_array_binary_search(). |
| |
498 * |
| |
499 * If the array is not sorted with respect to the \p cmp_func, the behavior |
| |
500 * is undefined. |
| |
501 * |
| |
502 * @param arr the array to search |
| |
503 * @param size the size of the array |
| |
504 * @param elem_size the size of one element |
| |
505 * @param elem the element to find |
| |
506 * @param cmp_func the compare function |
| |
507 * @return the index of the largest lower bound, or \p size |
| |
508 */ |
| |
509 cx_attr_nonnull |
| |
510 size_t cx_array_binary_search_inf( |
| |
511 const void *arr, |
| |
512 size_t size, |
| |
513 size_t elem_size, |
| |
514 const void *elem, |
| |
515 cx_compare_func cmp_func |
| |
516 ); |
| |
517 |
| |
518 /** |
| |
519 * Searches an item in a sorted array. |
| |
520 * |
| |
521 * If the array is not sorted with respect to the \p cmp_func, the behavior |
| |
522 * is undefined. |
| |
523 * |
| |
524 * @param arr the array to search |
| |
525 * @param size the size of the array |
| |
526 * @param elem_size the size of one element |
| |
527 * @param elem the element to find |
| |
528 * @param cmp_func the compare function |
| |
529 * @return the index of the element in the array, or \p size if the element |
| |
530 * cannot be found |
| |
531 */ |
| |
532 cx_attr_nonnull |
| |
533 size_t cx_array_binary_search( |
| |
534 const void *arr, |
| |
535 size_t size, |
| |
536 size_t elem_size, |
| |
537 const void *elem, |
| |
538 cx_compare_func cmp_func |
| |
539 ); |
| |
540 |
| |
541 /** |
| |
542 * Searches the smallest upper bound in a sorted array. |
| |
543 * |
| |
544 * In other words, this function returns the index of the smallest element |
| |
545 * in \p arr that is greater or equal to \p elem with respect to \p cmp_func. |
| |
546 * When no such element exists, \p size is returned. |
| |
547 * |
| |
548 * If \p elem is contained in the array, this is identical to |
| |
549 * #cx_array_binary_search(). |
| |
550 * |
| |
551 * If the array is not sorted with respect to the \p cmp_func, the behavior |
| |
552 * is undefined. |
| |
553 * |
| |
554 * @param arr the array to search |
| |
555 * @param size the size of the array |
| |
556 * @param elem_size the size of one element |
| |
557 * @param elem the element to find |
| |
558 * @param cmp_func the compare function |
| |
559 * @return the index of the smallest upper bound, or \p size |
| |
560 */ |
| |
561 cx_attr_nonnull |
| |
562 size_t cx_array_binary_search_sup( |
| |
563 const void *arr, |
| |
564 size_t size, |
| |
565 size_t elem_size, |
| |
566 const void *elem, |
| |
567 cx_compare_func cmp_func |
| |
568 ); |
| 212 |
569 |
| 213 /** |
570 /** |
| 214 * Swaps two array elements. |
571 * Swaps two array elements. |
| 215 * |
572 * |
| 216 * @param arr the array |
573 * @param arr the array |
| 217 * @param elem_size the element size |
574 * @param elem_size the element size |
| 218 * @param idx1 index of first element |
575 * @param idx1 index of first element |
| 219 * @param idx2 index of second element |
576 * @param idx2 index of second element |
| 220 */ |
577 */ |
| |
578 cx_attr_nonnull |
| 221 void cx_array_swap( |
579 void cx_array_swap( |
| 222 void *arr, |
580 void *arr, |
| 223 size_t elem_size, |
581 size_t elem_size, |
| 224 size_t idx1, |
582 size_t idx1, |
| 225 size_t idx2 |
583 size_t idx2 |
| 226 ) __attribute__((__nonnull__)); |
584 ); |
| 227 |
585 |
| 228 /** |
586 /** |
| 229 * Allocates an array list for storing elements with \p elem_size bytes each. |
587 * Allocates an array list for storing elements with \p elem_size bytes each. |
| 230 * |
588 * |
| 231 * If \p elem_size is CX_STORE_POINTERS, the created list will be created as if |
589 * If \p elem_size is CX_STORE_POINTERS, the created list will be created as if |
| 232 * cxListStorePointers() was called immediately after creation and the compare |
590 * cxListStorePointers() was called immediately after creation and the compare |
| 233 * function will be automatically set to cx_cmp_ptr(), if none is given. |
591 * function will be automatically set to cx_cmp_ptr(), if none is given. |
| 234 * |
592 * |
| 235 * @param allocator the allocator for allocating the list memory |
593 * @param allocator the allocator for allocating the list memory |
| 236 * (if \c NULL the cxDefaultAllocator will be used) |
594 * (if \c NULL, a default stdlib allocator will be used) |
| 237 * @param comparator the comparator for the elements |
595 * @param comparator the comparator for the elements |
| 238 * (if \c NULL, and the list is not storing pointers, sort and find |
596 * (if \c NULL, and the list is not storing pointers, sort and find |
| 239 * functions will not work) |
597 * functions will not work) |
| 240 * @param elem_size the size of each element in bytes |
598 * @param elem_size the size of each element in bytes |
| 241 * @param initial_capacity the initial number of elements the array can store |
599 * @param initial_capacity the initial number of elements the array can store |
| 242 * @return the created list |
600 * @return the created list |
| 243 */ |
601 */ |
| |
602 cx_attr_nodiscard |
| |
603 cx_attr_malloc |
| |
604 cx_attr_dealloc(cxListFree, 1) |
| 244 CxList *cxArrayListCreate( |
605 CxList *cxArrayListCreate( |
| 245 CxAllocator const *allocator, |
606 const CxAllocator *allocator, |
| 246 cx_compare_func comparator, |
607 cx_compare_func comparator, |
| 247 size_t elem_size, |
608 size_t elem_size, |
| 248 size_t initial_capacity |
609 size_t initial_capacity |
| 249 ); |
610 ); |
| 250 |
611 |