236 * @param allocator the allocator this reallocator shall be based on |
238 * @param allocator the allocator this reallocator shall be based on |
237 * @param stackmem the address of the array when the array is initially located |
239 * @param stackmem the address of the array when the array is initially located |
238 * on the stack or shall not reallocated in place |
240 * on the stack or shall not reallocated in place |
239 * @return an array reallocator |
241 * @return an array reallocator |
240 */ |
242 */ |
|
243 cx_attr_export |
241 CxArrayReallocator cx_array_reallocator( |
244 CxArrayReallocator cx_array_reallocator( |
242 const struct cx_allocator_s *allocator, |
245 const struct cx_allocator_s *allocator, |
243 const void *stackmem |
246 const void *stackmem |
244 ); |
247 ); |
245 |
248 |
272 * @retval zero success |
275 * @retval zero success |
273 * @retval non-zero failure |
276 * @retval non-zero failure |
274 * @see cx_array_reallocator() |
277 * @see cx_array_reallocator() |
275 */ |
278 */ |
276 cx_attr_nonnull_arg(1, 2, 3) |
279 cx_attr_nonnull_arg(1, 2, 3) |
|
280 cx_attr_export |
277 int cx_array_reserve( |
281 int cx_array_reserve( |
278 void **array, |
282 void **array, |
279 void *size, |
283 void *size, |
280 void *capacity, |
284 void *capacity, |
281 unsigned width, |
285 unsigned width, |
315 * @retval zero success |
319 * @retval zero success |
316 * @retval non-zero failure |
320 * @retval non-zero failure |
317 * @see cx_array_reallocator() |
321 * @see cx_array_reallocator() |
318 */ |
322 */ |
319 cx_attr_nonnull_arg(1, 2, 3, 6) |
323 cx_attr_nonnull_arg(1, 2, 3, 6) |
|
324 cx_attr_export |
320 int cx_array_copy( |
325 int cx_array_copy( |
321 void **target, |
326 void **target, |
322 void *size, |
327 void *size, |
323 void *capacity, |
328 void *capacity, |
324 unsigned width, |
329 unsigned width, |
473 * (@c NULL defaults to #cx_array_default_reallocator) |
478 * (@c NULL defaults to #cx_array_default_reallocator) |
474 * @retval zero success |
479 * @retval zero success |
475 * @retval non-zero failure |
480 * @retval non-zero failure |
476 */ |
481 */ |
477 cx_attr_nonnull_arg(1, 2, 3, 5) |
482 cx_attr_nonnull_arg(1, 2, 3, 5) |
|
483 cx_attr_export |
478 int cx_array_insert_sorted( |
484 int cx_array_insert_sorted( |
479 void **target, |
485 void **target, |
480 size_t *size, |
486 size_t *size, |
481 size_t *capacity, |
487 size_t *capacity, |
482 cx_compare_func cmp_func, |
488 cx_compare_func cmp_func, |
672 * @param elem_size the element size |
681 * @param elem_size the element size |
673 * @param idx1 index of first element |
682 * @param idx1 index of first element |
674 * @param idx2 index of second element |
683 * @param idx2 index of second element |
675 */ |
684 */ |
676 cx_attr_nonnull |
685 cx_attr_nonnull |
|
686 cx_attr_export |
677 void cx_array_swap( |
687 void cx_array_swap( |
678 void *arr, |
688 void *arr, |
679 size_t elem_size, |
689 size_t elem_size, |
680 size_t idx1, |
690 size_t idx1, |
681 size_t idx2 |
691 size_t idx2 |
682 ); |
692 ); |
683 |
693 |
684 /** |
694 /** |
685 * Allocates an array list for storing elements with @p elem_size bytes each. |
695 * Allocates an array list for storing elements with @p elem_size bytes each. |
686 * |
696 * |
687 * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if |
697 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
688 * cxListStorePointers() was called immediately after creation and the compare |
698 * copies of the added elements and the compare function will be automatically set |
689 * function will be automatically set to cx_cmp_ptr(), if none is given. |
699 * to cx_cmp_ptr(), if none is given. |
690 * |
700 * |
691 * @param allocator the allocator for allocating the list memory |
701 * @param allocator the allocator for allocating the list memory |
692 * (if @c NULL, a default stdlib allocator will be used) |
702 * (if @c NULL, a default stdlib allocator will be used) |
693 * @param comparator the comparator for the elements |
703 * @param comparator the comparator for the elements |
694 * (if @c NULL, and the list is not storing pointers, sort and find |
704 * (if @c NULL, and the list is not storing pointers, sort and find |
698 * @return the created list |
708 * @return the created list |
699 */ |
709 */ |
700 cx_attr_nodiscard |
710 cx_attr_nodiscard |
701 cx_attr_malloc |
711 cx_attr_malloc |
702 cx_attr_dealloc(cxListFree, 1) |
712 cx_attr_dealloc(cxListFree, 1) |
|
713 cx_attr_export |
703 CxList *cxArrayListCreate( |
714 CxList *cxArrayListCreate( |
704 const CxAllocator *allocator, |
715 const CxAllocator *allocator, |
705 cx_compare_func comparator, |
716 cx_compare_func comparator, |
706 size_t elem_size, |
717 size_t elem_size, |
707 size_t initial_capacity |
718 size_t initial_capacity |
712 * |
723 * |
713 * The list will use the cxDefaultAllocator and @em NO compare function. |
724 * The list will use the cxDefaultAllocator and @em NO compare function. |
714 * If you want to call functions that need a compare function, you have to |
725 * If you want to call functions that need a compare function, you have to |
715 * set it immediately after creation or use cxArrayListCreate(). |
726 * set it immediately after creation or use cxArrayListCreate(). |
716 * |
727 * |
717 * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if |
728 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of |
718 * cxListStorePointers() was called immediately after creation and the compare |
729 * copies of the added elements and the compare function will be automatically set |
719 * function will be automatically set to cx_cmp_ptr(). |
730 * to cx_cmp_ptr(), if none is given. |
720 * |
731 * |
721 * @param elem_size (@c size_t) the size of each element in bytes |
732 * @param elem_size (@c size_t) the size of each element in bytes |
722 * @param initial_capacity (@c size_t) the initial number of elements the array can store |
733 * @param initial_capacity (@c size_t) the initial number of elements the array can store |
723 * @return the created list |
734 * @return the created list |
724 */ |
735 */ |