src/cx/array_list.h

changeset 1180
4c3a69b9723a
parent 1111
78eeeb950883
equal deleted inserted replaced
1179:ca4c6f590a08 1180:4c3a69b9723a
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 stack buffer
48 * when swapped. 48 * when swapped.
49 */ 49 */
50 cx_attr_export
50 extern const unsigned cx_array_swap_sbo_size; 51 extern const unsigned cx_array_swap_sbo_size;
51 52
52 /** 53 /**
53 * Declares variables for an array that can be used with the convenience macros. 54 * Declares variables for an array that can be used with the convenience macros.
54 * 55 *
216 typedef struct cx_array_reallocator_s CxArrayReallocator; 217 typedef struct cx_array_reallocator_s CxArrayReallocator;
217 218
218 /** 219 /**
219 * A default stdlib-based array reallocator. 220 * A default stdlib-based array reallocator.
220 */ 221 */
222 cx_attr_export
221 extern CxArrayReallocator *cx_array_default_reallocator; 223 extern CxArrayReallocator *cx_array_default_reallocator;
222 224
223 /** 225 /**
224 * Creates a new array reallocator. 226 * Creates a new array reallocator.
225 * 227 *
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,
599 * @return the index of the largest lower bound, or @p size 605 * @return the index of the largest lower bound, or @p size
600 * @see cx_array_binary_search_sup() 606 * @see cx_array_binary_search_sup()
601 * @see cx_array_binary_search() 607 * @see cx_array_binary_search()
602 */ 608 */
603 cx_attr_nonnull 609 cx_attr_nonnull
610 cx_attr_export
604 size_t cx_array_binary_search_inf( 611 size_t cx_array_binary_search_inf(
605 const void *arr, 612 const void *arr,
606 size_t size, 613 size_t size,
607 size_t elem_size, 614 size_t elem_size,
608 const void *elem, 615 const void *elem,
624 * cannot be found 631 * cannot be found
625 * @see cx_array_binary_search_inf() 632 * @see cx_array_binary_search_inf()
626 * @see cx_array_binary_search_sup() 633 * @see cx_array_binary_search_sup()
627 */ 634 */
628 cx_attr_nonnull 635 cx_attr_nonnull
636 cx_attr_export
629 size_t cx_array_binary_search( 637 size_t cx_array_binary_search(
630 const void *arr, 638 const void *arr,
631 size_t size, 639 size_t size,
632 size_t elem_size, 640 size_t elem_size,
633 const void *elem, 641 const void *elem,
655 * @return the index of the smallest upper bound, or @p size 663 * @return the index of the smallest upper bound, or @p size
656 * @see cx_array_binary_search_inf() 664 * @see cx_array_binary_search_inf()
657 * @see cx_array_binary_search() 665 * @see cx_array_binary_search()
658 */ 666 */
659 cx_attr_nonnull 667 cx_attr_nonnull
668 cx_attr_export
660 size_t cx_array_binary_search_sup( 669 size_t cx_array_binary_search_sup(
661 const void *arr, 670 const void *arr,
662 size_t size, 671 size_t size,
663 size_t elem_size, 672 size_t elem_size,
664 const void *elem, 673 const void *elem,
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
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

mercurial