| 243 * The @p width in bytes refers to the size and capacity. |
243 * The @p width in bytes refers to the size and capacity. |
| 244 * Both must have the same width. |
244 * Both must have the same width. |
| 245 * 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 |
| 246 * architecture. If set to zero, the native word width is used. |
246 * architecture. If set to zero, the native word width is used. |
| 247 * |
247 * |
| |
248 * @note This function will reserve the minimum required capacity to hold |
| |
249 * the additional elements and does not perform an overallocation. |
| |
250 * |
| 248 * @param array a pointer to the target array |
251 * @param array a pointer to the target array |
| 249 * @param size a pointer to the size of the array |
252 * @param size a pointer to the size of the array |
| 250 * @param capacity a pointer to the capacity of the array |
253 * @param capacity a pointer to the capacity of the array |
| 251 * @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 |
| 252 * @param elem_size the size of one element |
255 * @param elem_size the size of one element |
| 277 * |
280 * |
| 278 * The @p width in bytes refers to the size and capacity. |
281 * The @p width in bytes refers to the size and capacity. |
| 279 * Both must have the same width. |
282 * Both must have the same width. |
| 280 * 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 |
| 281 * 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. |
| 282 * |
288 * |
| 283 * @param target a pointer to the target array |
289 * @param target a pointer to the target array |
| 284 * @param size a pointer to the size of the target array |
290 * @param size a pointer to the size of the target array |
| 285 * @param capacity a pointer to the capacity of the target array |
291 * @param capacity a pointer to the capacity of the target array |
| 286 * @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 |
| 291 * @param reallocator the array reallocator to use |
297 * @param reallocator the array reallocator to use |
| 292 * (@c NULL defaults to #cx_array_default_reallocator) |
298 * (@c NULL defaults to #cx_array_default_reallocator) |
| 293 * @retval zero success |
299 * @retval zero success |
| 294 * @retval non-zero failure |
300 * @retval non-zero failure |
| 295 * @see cx_array_reallocator() |
301 * @see cx_array_reallocator() |
| |
302 * @see cx_array_reserve() |
| 296 */ |
303 */ |
| 297 cx_attr_nonnull_arg(1, 2, 3, 6) |
304 cx_attr_nonnull_arg(1, 2, 3, 6) |
| 298 CX_EXPORT int cx_array_copy(void **target, void *size, void *capacity, unsigned width, |
305 CX_EXPORT int cx_array_copy(void **target, void *size, void *capacity, unsigned width, |
| 299 size_t index, const void *src, size_t elem_size, size_t elem_count, |
306 size_t index, const void *src, size_t elem_size, size_t elem_count, |
| 300 CxArrayReallocator *reallocator); |
307 CxArrayReallocator *reallocator); |
| 667 * |
674 * |
| 668 * 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 |
| 669 * in @p arr that is less or equal to @p elem with respect to @p cmp_func. |
676 * in @p arr that is less or equal to @p elem with respect to @p cmp_func. |
| 670 * When no such element exists, @p size is returned. |
677 * When no such element exists, @p size is returned. |
| 671 * |
678 * |
| |
679 * When such an element exists more than once, the largest index of all those |
| |
680 * elements is returned. |
| |
681 * |
| 672 * If @p elem is contained in the array, this is identical to |
682 * If @p elem is contained in the array, this is identical to |
| 673 * #cx_array_binary_search(). |
683 * #cx_array_binary_search(). |
| 674 * |
684 * |
| 675 * If the array is not sorted with respect to the @p cmp_func, the behavior |
685 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 676 * is undefined. |
686 * is undefined. |
| 688 CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size, |
698 CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size, |
| 689 size_t elem_size, const void *elem, cx_compare_func cmp_func); |
699 size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 690 |
700 |
| 691 /** |
701 /** |
| 692 * Searches an item in a sorted array. |
702 * Searches an item in a sorted array. |
| |
703 * |
| |
704 * When such an element exists more than once, the largest index of all those |
| |
705 * elements is returned. |
| 693 * |
706 * |
| 694 * If the array is not sorted with respect to the @p cmp_func, the behavior |
707 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 695 * is undefined. |
708 * is undefined. |
| 696 * |
709 * |
| 697 * @param arr the array to search |
710 * @param arr the array to search |
| 713 * |
726 * |
| 714 * In other words, this function returns the index of the smallest element |
727 * In other words, this function returns the index of the smallest element |
| 715 * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. |
728 * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. |
| 716 * When no such element exists, @p size is returned. |
729 * When no such element exists, @p size is returned. |
| 717 * |
730 * |
| |
731 * When such an element exists more than once, the smallest index of all those |
| |
732 * elements is returned. |
| |
733 * |
| 718 * If @p elem is contained in the array, this is identical to |
734 * If @p elem is contained in the array, this is identical to |
| 719 * #cx_array_binary_search(). |
735 * #cx_array_binary_search(). |
| 720 * |
736 * |
| 721 * If the array is not sorted with respect to the @p cmp_func, the behavior |
737 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| 722 * is undefined. |
738 * is undefined. |