ucx/cx/array_list.h

changeset 22
112b85020dc9
parent 21
5ea41679e15d
child 23
b26390e77237
equal deleted inserted replaced
21:5ea41679e15d 22:112b85020dc9
42 #ifdef __cplusplus 42 #ifdef __cplusplus
43 extern "C" { 43 extern "C" {
44 #endif 44 #endif
45 45
46 /** 46 /**
47 * The maximum item size in an array list that fits into stack buffer 47 * The maximum item size in an array list that fits into
48 * when swapped. 48 * a stack buffer when swapped.
49 */ 49 */
50 cx_attr_export 50 CX_EXPORT extern const unsigned cx_array_swap_sbo_size;
51 extern const unsigned cx_array_swap_sbo_size;
52 51
53 /** 52 /**
54 * Declares variables for an array that can be used with the convenience macros. 53 * Declares variables for an array that can be used with the convenience macros.
55 * 54 *
56 * @par Examples 55 * @par Examples
82 /** Array capacity. */ size_type name##_capacity 81 /** Array capacity. */ size_type name##_capacity
83 82
84 /** 83 /**
85 * Declares variables for an array that can be used with the convenience macros. 84 * Declares variables for an array that can be used with the convenience macros.
86 * 85 *
87 * The size and capacity variables will have @c size_t type. 86 * The size and capacity variables will have type @c size_t.
88 * Use #CX_ARRAY_DECLARE_SIZED() to specify a different type. 87 * Use #CX_ARRAY_DECLARE_SIZED() to specify a different type.
89 * 88 *
90 * @par Examples 89 * @par Examples
91 * @code 90 * @code
92 * // int array 91 * // int array
145 * 144 *
146 * 145 *
147 * const CxAllocator *al = // ... 146 * const CxAllocator *al = // ...
148 * cx_array_initialize_a(al, myarray, 128); 147 * cx_array_initialize_a(al, myarray, 128);
149 * // ... 148 * // ...
150 * cxFree(al, myarray); // don't forget to free with same allocator 149 * cxFree(al, myarray); // remember to free with the same allocator
151 * @endcode 150 * @endcode
152 * 151 *
153 * @param allocator (@c CxAllocator*) the allocator 152 * @param allocator (@c CxAllocator*) the allocator
154 * @param array the name of the array 153 * @param array the name of the array
155 * @param capacity the initial capacity 154 * @param capacity the initial capacity
170 struct cx_array_reallocator_s { 169 struct cx_array_reallocator_s {
171 /** 170 /**
172 * Reallocates space for the given array. 171 * Reallocates space for the given array.
173 * 172 *
174 * Implementations are not required to free the original array. 173 * Implementations are not required to free the original array.
175 * This allows reallocation of static memory by allocating heap memory 174 * This allows reallocation of static or stack memory by allocating heap memory
176 * and copying the array contents. The information in the custom fields of 175 * and copying the array contents; namely when @c stack_ptr in this struct
177 * the referenced allocator can be used to track the state of the memory 176 * is not @c NULL and @p array equals @c stack_ptr.
178 * or to transport other additional data.
179 * 177 *
180 * @param array the array to reallocate 178 * @param array the array to reallocate
181 * @param old_capacity the old number of elements 179 * @param old_capacity the old number of elements
182 * @param new_capacity the new number of elements 180 * @param new_capacity the new number of elements
183 * @param elem_size the size of each element 181 * @param elem_size the size of each element
184 * @param alloc a reference to this allocator 182 * @param alloc a reference to this allocator
185 * @return a pointer to the reallocated memory or @c NULL on failure 183 * @return a pointer to the reallocated memory or @c NULL on failure
186 */ 184 */
187 cx_attr_nodiscard 185 void *(*realloc)( void *array, size_t old_capacity, size_t new_capacity,
188 cx_attr_nonnull_arg(5) 186 size_t elem_size, struct cx_array_reallocator_s *alloc);
189 cx_attr_allocsize(3, 4)
190 void *(*realloc)(
191 void *array,
192 size_t old_capacity,
193 size_t new_capacity,
194 size_t elem_size,
195 struct cx_array_reallocator_s *alloc
196 );
197 187
198 /** 188 /**
199 * Custom data pointer. 189 * The allocator that shall be used for the reallocations.
200 */ 190 */
201 void *ptr1; 191 const CxAllocator *allocator;
202 /** 192 /**
203 * Custom data pointer. 193 * Optional pointer to stack memory
194 * if the array is originally located on the stack.
204 */ 195 */
205 void *ptr2; 196 const void *stack_ptr;
206 /**
207 * Custom data integer.
208 */
209 size_t int1;
210 /**
211 * Custom data integer.
212 */
213 size_t int2;
214 }; 197 };
215 198
216 /** 199 /**
217 * Typedef for the array reallocator struct. 200 * Typedef for the array reallocator struct.
218 */ 201 */
219 typedef struct cx_array_reallocator_s CxArrayReallocator; 202 typedef struct cx_array_reallocator_s CxArrayReallocator;
220 203
221 /** 204 /**
222 * A default array reallocator that is based on the cxDefaultAllocator. 205 * A default array reallocator that is based on the cxDefaultAllocator.
223 */ 206 */
224 cx_attr_export 207 CX_EXPORT extern CxArrayReallocator *cx_array_default_reallocator;
225 extern CxArrayReallocator *cx_array_default_reallocator;
226 208
227 /** 209 /**
228 * Creates a new array reallocator. 210 * Creates a new array reallocator.
229 * 211 *
230 * When @p allocator is @c NULL, the cxDefaultAllocator will be used. 212 * When @p allocator is @c NULL, the cxDefaultAllocator will be used.
231 * 213 *
232 * When @p stackmem is not @c NULL, the reallocator is supposed to be used 214 * When @p stack_ptr is not @c NULL, the reallocator is supposed to be used
233 * @em only for the specific array that is initially located at @p stackmem. 215 * @em only for the specific array initially located at @p stack_ptr.
234 * When reallocation is needed, the reallocator checks, if the array is 216 * When reallocation is needed, the reallocator checks if the array is
235 * still located at @p stackmem and copies the contents to the heap. 217 * still located at @p stack_ptr and copies the contents to the heap.
236 * 218 *
237 * @note Invoking this function with both arguments @c NULL will return a 219 * @note Invoking this function with both arguments being @c NULL will return a
238 * reallocator that behaves like #cx_array_default_reallocator. 220 * reallocator that behaves like #cx_array_default_reallocator.
239 * 221 *
240 * @param allocator the allocator this reallocator shall be based on 222 * @param allocator the allocator this reallocator shall be based on
241 * @param stackmem the address of the array when the array is initially located 223 * @param stack_ptr the address of the array when the array is initially located
242 * on the stack or shall not reallocated in place 224 * on the stack or shall not reallocate in place
243 * @return an array reallocator 225 * @return an array reallocator
244 */ 226 */
245 cx_attr_export 227 CX_EXPORT CxArrayReallocator cx_array_reallocator(
246 CxArrayReallocator cx_array_reallocator( 228 const struct cx_allocator_s *allocator, const void *stack_ptr);
247 const struct cx_allocator_s *allocator,
248 const void *stackmem
249 );
250 229
251 /** 230 /**
252 * Reserves memory for additional elements. 231 * Reserves memory for additional elements.
253 * 232 *
254 * This function checks if the @p capacity of the array is sufficient to hold 233 * This function checks if the @p capacity of the array is sufficient to hold
261 * with one single cx_array_reserve() and then - after guaranteeing a 240 * with one single cx_array_reserve() and then - after guaranteeing a
262 * sufficient capacity - use simple memmove() or memcpy(). 241 * sufficient capacity - use simple memmove() or memcpy().
263 * 242 *
264 * The @p width in bytes refers to the size and capacity. 243 * The @p width in bytes refers to the size and capacity.
265 * Both must have the same width. 244 * Both must have the same width.
266 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit 245 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit
267 * architecture. If set to zero, the native word width is used. 246 * architecture. If set to zero, the native word width is used.
247 *
248 * @note This function will reserve the minimum required capacity to hold
249 * the additional elements and does not perform an overallocation.
268 * 250 *
269 * @param array a pointer to the target array 251 * @param array a pointer to the target array
270 * @param size a pointer to the size of the array 252 * @param size a pointer to the size of the array
271 * @param capacity a pointer to the capacity of the array 253 * @param capacity a pointer to the capacity of the array
272 * @param width the width in bytes for the @p size and @p capacity or zero for default 254 * @param width the width in bytes for the @p size and @p capacity or zero for default
277 * @retval zero success 259 * @retval zero success
278 * @retval non-zero failure 260 * @retval non-zero failure
279 * @see cx_array_reallocator() 261 * @see cx_array_reallocator()
280 */ 262 */
281 cx_attr_nonnull_arg(1, 2, 3) 263 cx_attr_nonnull_arg(1, 2, 3)
282 cx_attr_export 264 CX_EXPORT int cx_array_reserve(void **array, void *size, void *capacity,
283 int cx_array_reserve( 265 unsigned width, size_t elem_size, size_t elem_count,
284 void **array, 266 CxArrayReallocator *reallocator);
285 void *size,
286 void *capacity,
287 unsigned width,
288 size_t elem_size,
289 size_t elem_count,
290 CxArrayReallocator *reallocator
291 );
292 267
293 /** 268 /**
294 * Copies elements from one array to another. 269 * Copies elements from one array to another.
295 * 270 *
296 * The elements are copied to the @p target array at the specified @p index, 271 * The elements are copied to the @p target array at the specified @p index,
297 * overwriting possible elements. The @p index does not need to be in range of 272 * overwriting possible elements. The @p index does not need to be in range of
298 * the current array @p size. If the new index plus the number of elements added 273 * the current array @p size. If the new index plus the number of elements added
299 * would extend the array's size, the remaining @p capacity is used. 274 * extends the array's size, the remaining @p capacity is used.
300 * 275 *
301 * If the @p capacity is also insufficient to hold the new data, a reallocation 276 * If the @p capacity is also insufficient to hold the new data, a reallocation
302 * attempt is made with the specified @p reallocator. 277 * attempt is made with the specified @p reallocator.
303 * You can create your own reallocator by hand, use #cx_array_default_reallocator, 278 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
304 * or use the convenience function cx_array_reallocator() to create a custom reallocator. 279 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
305 * 280 *
306 * The @p width in bytes refers to the size and capacity. 281 * The @p width in bytes refers to the size and capacity.
307 * Both must have the same width. 282 * Both must have the same width.
308 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64 bit 283 * Supported are 0, 1, 2, and 4, as well as 8 if running on a 64-bit
309 * architecture. If set to zero, the native word width is used. 284 * architecture. If set to zero, the native word width is used.
285 *
286 * @note When this function does reallocate the array, it may allocate more
287 * space than required to avoid further allocations in the near future.
310 * 288 *
311 * @param target a pointer to the target array 289 * @param target a pointer to the target array
312 * @param size a pointer to the size of the target array 290 * @param size a pointer to the size of the target array
313 * @param capacity a pointer to the capacity of the target array 291 * @param capacity a pointer to the capacity of the target array
314 * @param width the width in bytes for the @p size and @p capacity or zero for default 292 * @param width the width in bytes for the @p size and @p capacity or zero for default
319 * @param reallocator the array reallocator to use 297 * @param reallocator the array reallocator to use
320 * (@c NULL defaults to #cx_array_default_reallocator) 298 * (@c NULL defaults to #cx_array_default_reallocator)
321 * @retval zero success 299 * @retval zero success
322 * @retval non-zero failure 300 * @retval non-zero failure
323 * @see cx_array_reallocator() 301 * @see cx_array_reallocator()
302 * @see cx_array_reserve()
324 */ 303 */
325 cx_attr_nonnull_arg(1, 2, 3, 6) 304 cx_attr_nonnull_arg(1, 2, 3, 6)
326 cx_attr_export 305 CX_EXPORT int cx_array_copy(void **target, void *size, void *capacity, unsigned width,
327 int cx_array_copy( 306 size_t index, const void *src, size_t elem_size, size_t elem_count,
328 void **target, 307 CxArrayReallocator *reallocator);
329 void *size,
330 void *capacity,
331 unsigned width,
332 size_t index,
333 const void *src,
334 size_t elem_size,
335 size_t elem_count,
336 CxArrayReallocator *reallocator
337 );
338 308
339 /** 309 /**
340 * Convenience macro that uses cx_array_copy() with a default layout and 310 * Convenience macro that uses cx_array_copy() with a default layout and
341 * the specified reallocator. 311 * the specified reallocator.
342 * 312 *
480 * (@c NULL defaults to #cx_array_default_reallocator) 450 * (@c NULL defaults to #cx_array_default_reallocator)
481 * @retval zero success 451 * @retval zero success
482 * @retval non-zero failure 452 * @retval non-zero failure
483 */ 453 */
484 cx_attr_nonnull_arg(1, 2, 3, 5) 454 cx_attr_nonnull_arg(1, 2, 3, 5)
485 cx_attr_export 455 CX_EXPORT int cx_array_insert_sorted(void **target, size_t *size, size_t *capacity,
486 int cx_array_insert_sorted( 456 cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count,
487 void **target, 457 CxArrayReallocator *reallocator);
488 size_t *size,
489 size_t *capacity,
490 cx_compare_func cmp_func,
491 const void *src,
492 size_t elem_size,
493 size_t elem_count,
494 CxArrayReallocator *reallocator
495 );
496 458
497 /** 459 /**
498 * Inserts an element into a sorted array. 460 * Inserts an element into a sorted array.
499 * 461 *
500 * If the target array is not already sorted with respect 462 * If the target array is not already sorted with respect
501 * to the specified @p cmp_func, the behavior is undefined. 463 * to the specified @p cmp_func, the behavior is undefined.
502 * 464 *
503 * If the capacity is insufficient to hold the new data, a reallocation 465 * If the capacity is not enough to hold the new data, a reallocation
504 * attempt is made. 466 * attempt is made.
505 * 467 *
506 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type. 468 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type.
507 * It is important, however, that @p size and @p capacity are pointers to 469 * It is important, however, that @p size and @p capacity are pointers to
508 * variables of the same type. 470 * variables of the same type.
583 * @see CX_ARRAY_DECLARE() 545 * @see CX_ARRAY_DECLARE()
584 * @see cx_array_simple_insert_sorted_a() 546 * @see cx_array_simple_insert_sorted_a()
585 */ 547 */
586 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \ 548 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \
587 cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func) 549 cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func)
550
551
552 /**
553 * Inserts a sorted array into another sorted array, avoiding duplicates.
554 *
555 * If either the target or the source array is not already sorted with respect
556 * to the specified @p cmp_func, the behavior is undefined.
557 *
558 * If the capacity is insufficient to hold the new data, a reallocation
559 * attempt is made.
560 * You can create your own reallocator by hand, use #cx_array_default_reallocator,
561 * or use the convenience function cx_array_reallocator() to create a custom reallocator.
562 *
563 * @param target a pointer to the target array
564 * @param size a pointer to the size of the target array
565 * @param capacity a pointer to the capacity of the target array
566 * @param cmp_func the compare function for the elements
567 * @param src the source array
568 * @param elem_size the size of one element
569 * @param elem_count the number of elements to insert
570 * @param reallocator the array reallocator to use
571 * (@c NULL defaults to #cx_array_default_reallocator)
572 * @retval zero success
573 * @retval non-zero failure
574 */
575 cx_attr_nonnull_arg(1, 2, 3, 5)
576 CX_EXPORT int cx_array_insert_unique(void **target, size_t *size, size_t *capacity,
577 cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count,
578 CxArrayReallocator *reallocator);
579
580 /**
581 * Inserts an element into a sorted array if it does not exist.
582 *
583 * If the target array is not already sorted with respect
584 * to the specified @p cmp_func, the behavior is undefined.
585 *
586 * If the capacity is insufficient to hold the new data, a reallocation
587 * attempt is made.
588 *
589 * The \@ SIZE_TYPE is flexible and can be any unsigned integer type.
590 * It is important, however, that @p size and @p capacity are pointers to
591 * variables of the same type.
592 *
593 * @param target (@c void**) a pointer to the target array
594 * @param size (@c SIZE_TYPE*) a pointer to the size of the target array
595 * @param capacity (@c SIZE_TYPE*) a pointer to the capacity of the target array
596 * @param elem_size (@c size_t) the size of one element
597 * @param elem (@c void*) a pointer to the element to add
598 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
599 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
600 * @retval zero success (also when the element was already present)
601 * @retval non-zero failure
602 */
603 #define cx_array_add_unique(target, size, capacity, elem_size, elem, cmp_func, reallocator) \
604 cx_array_insert_unique((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator)
605
606 /**
607 * Convenience macro for cx_array_add_unique() with a default
608 * layout and the specified reallocator.
609 *
610 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
611 * @param array the name of the array (NOT a pointer or alias to the array)
612 * @param elem the element to add (NOT a pointer, address is automatically taken)
613 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
614 * @retval zero success
615 * @retval non-zero failure
616 * @see CX_ARRAY_DECLARE()
617 * @see cx_array_simple_add_unique()
618 */
619 #define cx_array_simple_add_unique_a(reallocator, array, elem, cmp_func) \
620 cx_array_add_unique(&array, &(array##_size), &(array##_capacity), \
621 sizeof((array)[0]), &(elem), cmp_func, reallocator)
622
623 /**
624 * Convenience macro for cx_array_add_unique() with a default
625 * layout and the default reallocator.
626 *
627 * @param array the name of the array (NOT a pointer or alias to the array)
628 * @param elem the element to add (NOT a pointer, address is automatically taken)
629 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
630 * @retval zero success
631 * @retval non-zero failure
632 * @see CX_ARRAY_DECLARE()
633 * @see cx_array_simple_add_unique_a()
634 */
635 #define cx_array_simple_add_unique(array, elem, cmp_func) \
636 cx_array_simple_add_unique_a(NULL, array, elem, cmp_func)
637
638 /**
639 * Convenience macro for cx_array_insert_unique() with a default
640 * layout and the specified reallocator.
641 *
642 * @param reallocator (@c CxArrayReallocator*) the array reallocator to use
643 * @param array the name of the array (NOT a pointer or alias to the array)
644 * @param src (@c void*) pointer to the source array
645 * @param n (@c size_t) number of elements in the source array
646 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
647 * @retval zero success
648 * @retval non-zero failure
649 * @see CX_ARRAY_DECLARE()
650 * @see cx_array_simple_insert_unique()
651 */
652 #define cx_array_simple_insert_unique_a(reallocator, array, src, n, cmp_func) \
653 cx_array_insert_unique((void**)(&array), &(array##_size), &(array##_capacity), \
654 cmp_func, src, sizeof((array)[0]), n, reallocator)
655
656 /**
657 * Convenience macro for cx_array_insert_unique() with a default
658 * layout and the default reallocator.
659 *
660 * @param array the name of the array (NOT a pointer or alias to the array)
661 * @param src (@c void*) pointer to the source array
662 * @param n (@c size_t) number of elements in the source array
663 * @param cmp_func (@c cx_cmp_func) the compare function for the elements
664 * @retval zero success
665 * @retval non-zero failure
666 * @see CX_ARRAY_DECLARE()
667 * @see cx_array_simple_insert_unique_a()
668 */
669 #define cx_array_simple_insert_unique(array, src, n, cmp_func) \
670 cx_array_simple_insert_unique_a(NULL, array, src, n, cmp_func)
588 671
589 /** 672 /**
590 * Searches the largest lower bound in a sorted array. 673 * Searches the largest lower bound in a sorted array.
591 * 674 *
592 * In other words, this function returns the index of the largest element 675 * In other words, this function returns the index of the largest element
607 * @return the index of the largest lower bound, or @p size 690 * @return the index of the largest lower bound, or @p size
608 * @see cx_array_binary_search_sup() 691 * @see cx_array_binary_search_sup()
609 * @see cx_array_binary_search() 692 * @see cx_array_binary_search()
610 */ 693 */
611 cx_attr_nonnull 694 cx_attr_nonnull
612 cx_attr_export 695 CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size,
613 size_t cx_array_binary_search_inf( 696 size_t elem_size, const void *elem, cx_compare_func cmp_func);
614 const void *arr,
615 size_t size,
616 size_t elem_size,
617 const void *elem,
618 cx_compare_func cmp_func
619 );
620 697
621 /** 698 /**
622 * Searches an item in a sorted array. 699 * Searches an item in a sorted array.
623 * 700 *
624 * If the array is not sorted with respect to the @p cmp_func, the behavior 701 * If the array is not sorted with respect to the @p cmp_func, the behavior
633 * cannot be found 710 * cannot be found
634 * @see cx_array_binary_search_inf() 711 * @see cx_array_binary_search_inf()
635 * @see cx_array_binary_search_sup() 712 * @see cx_array_binary_search_sup()
636 */ 713 */
637 cx_attr_nonnull 714 cx_attr_nonnull
638 cx_attr_export 715 CX_EXPORT size_t cx_array_binary_search(const void *arr, size_t size,
639 size_t cx_array_binary_search( 716 size_t elem_size, const void *elem, cx_compare_func cmp_func);
640 const void *arr,
641 size_t size,
642 size_t elem_size,
643 const void *elem,
644 cx_compare_func cmp_func
645 );
646 717
647 /** 718 /**
648 * Searches the smallest upper bound in a sorted array. 719 * Searches the smallest upper bound in a sorted array.
649 * 720 *
650 * In other words, this function returns the index of the smallest element 721 * In other words, this function returns the index of the smallest element
665 * @return the index of the smallest upper bound, or @p size 736 * @return the index of the smallest upper bound, or @p size
666 * @see cx_array_binary_search_inf() 737 * @see cx_array_binary_search_inf()
667 * @see cx_array_binary_search() 738 * @see cx_array_binary_search()
668 */ 739 */
669 cx_attr_nonnull 740 cx_attr_nonnull
670 cx_attr_export 741 CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size,
671 size_t cx_array_binary_search_sup( 742 size_t elem_size, const void *elem, cx_compare_func cmp_func);
672 const void *arr,
673 size_t size,
674 size_t elem_size,
675 const void *elem,
676 cx_compare_func cmp_func
677 );
678 743
679 /** 744 /**
680 * Swaps two array elements. 745 * Swaps two array elements.
681 * 746 *
682 * @param arr the array 747 * @param arr the array
683 * @param elem_size the element size 748 * @param elem_size the element size
684 * @param idx1 index of first element 749 * @param idx1 index of the first element
685 * @param idx2 index of second element 750 * @param idx2 index of the second element
686 */ 751 */
687 cx_attr_nonnull 752 cx_attr_nonnull
688 cx_attr_export 753 CX_EXPORT void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2);
689 void cx_array_swap(
690 void *arr,
691 size_t elem_size,
692 size_t idx1,
693 size_t idx2
694 );
695 754
696 /** 755 /**
697 * Allocates an array list for storing elements with @p elem_size bytes each. 756 * Allocates an array list for storing elements with @p elem_size bytes each.
698 * 757 *
699 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of 758 * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
700 * copies of the added elements and the compare function will be automatically set 759 * copies of the added elements, and the compare function will be automatically set
701 * to cx_cmp_ptr(), if none is given. 760 * to cx_cmp_ptr(), if none is given.
702 * 761 *
703 * @param allocator the allocator for allocating the list memory 762 * @param allocator the allocator for allocating the list memory
704 * (if @c NULL, the cxDefaultAllocator will be used) 763 * (if @c NULL, the cxDefaultAllocator will be used)
705 * @param comparator the comparator for the elements 764 * @param comparator the comparator for the elements
710 * @return the created list 769 * @return the created list
711 */ 770 */
712 cx_attr_nodiscard 771 cx_attr_nodiscard
713 cx_attr_malloc 772 cx_attr_malloc
714 cx_attr_dealloc(cxListFree, 1) 773 cx_attr_dealloc(cxListFree, 1)
715 cx_attr_export 774 CX_EXPORT CxList *cxArrayListCreate(const CxAllocator *allocator,
716 CxList *cxArrayListCreate( 775 cx_compare_func comparator, size_t elem_size, size_t initial_capacity);
717 const CxAllocator *allocator,
718 cx_compare_func comparator,
719 size_t elem_size,
720 size_t initial_capacity
721 );
722 776
723 /** 777 /**
724 * Allocates an array list for storing elements with @p elem_size bytes each. 778 * Allocates an array list for storing elements with @p elem_size bytes each.
725 * 779 *
726 * The list will use the cxDefaultAllocator and @em NO compare function. 780 * The list will use the cxDefaultAllocator and @em NO compare function.

mercurial