| 705 */ |
705 */ |
| 706 cx_attr_nonnull |
706 cx_attr_nonnull |
| 707 CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size, |
707 CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size, |
| 708 size_t elem_size, const void *elem, cx_compare_func cmp_func); |
708 size_t elem_size, const void *elem, cx_compare_func cmp_func); |
| 709 |
709 |
| |
710 |
| |
711 /** |
| |
712 * Searches the largest lower bound in a sorted array. |
| |
713 * |
| |
714 * In other words, this function returns the index of the largest element |
| |
715 * in @p arr that is less or equal to @p elem with respect to @p cmp_func. |
| |
716 * When no such element exists, @p size is returned. |
| |
717 * |
| |
718 * When such an element exists more than once, the largest index of all those |
| |
719 * elements is returned. |
| |
720 * |
| |
721 * If @p elem is contained in the array, this is identical to |
| |
722 * #cx_array_binary_search(). |
| |
723 * |
| |
724 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| |
725 * is undefined. |
| |
726 * |
| |
727 * @param arr the array to search |
| |
728 * @param size the size of the array |
| |
729 * @param elem_size the size of one element |
| |
730 * @param elem the element to find |
| |
731 * @param cmp_func the compare function |
| |
732 * @param context the context for the compare function |
| |
733 * @return the index of the largest lower bound, or @p size |
| |
734 * @see cx_array_binary_search_sup() |
| |
735 * @see cx_array_binary_search() |
| |
736 */ |
| |
737 cx_attr_nonnull |
| |
738 CX_EXPORT size_t cx_array_binary_search_inf_c(const void *arr, size_t size, |
| |
739 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| |
740 |
| |
741 /** |
| |
742 * Searches an item in a sorted array. |
| |
743 * |
| |
744 * When such an element exists more than once, the largest index of all those |
| |
745 * elements is returned. |
| |
746 * |
| |
747 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| |
748 * is undefined. |
| |
749 * |
| |
750 * @param arr the array to search |
| |
751 * @param size the size of the array |
| |
752 * @param elem_size the size of one element |
| |
753 * @param elem the element to find |
| |
754 * @param cmp_func the compare function |
| |
755 * @param context the context for the compare function |
| |
756 * @return the index of the element in the array, or @p size if the element |
| |
757 * cannot be found |
| |
758 * @see cx_array_binary_search_inf() |
| |
759 * @see cx_array_binary_search_sup() |
| |
760 */ |
| |
761 cx_attr_nonnull |
| |
762 CX_EXPORT size_t cx_array_binary_search_c(const void *arr, size_t size, |
| |
763 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| |
764 |
| |
765 /** |
| |
766 * Searches the smallest upper bound in a sorted array. |
| |
767 * |
| |
768 * In other words, this function returns the index of the smallest element |
| |
769 * in @p arr that is greater or equal to @p elem with respect to @p cmp_func. |
| |
770 * When no such element exists, @p size is returned. |
| |
771 * |
| |
772 * When such an element exists more than once, the smallest index of all those |
| |
773 * elements is returned. |
| |
774 * |
| |
775 * If @p elem is contained in the array, this is identical to |
| |
776 * #cx_array_binary_search(). |
| |
777 * |
| |
778 * If the array is not sorted with respect to the @p cmp_func, the behavior |
| |
779 * is undefined. |
| |
780 * |
| |
781 * @param arr the array to search |
| |
782 * @param size the size of the array |
| |
783 * @param elem_size the size of one element |
| |
784 * @param elem the element to find |
| |
785 * @param cmp_func the compare function |
| |
786 * @param context the context for the compare function |
| |
787 * @return the index of the smallest upper bound, or @p size |
| |
788 * @see cx_array_binary_search_inf() |
| |
789 * @see cx_array_binary_search() |
| |
790 */ |
| |
791 cx_attr_nonnull |
| |
792 CX_EXPORT size_t cx_array_binary_search_sup_c(const void *arr, size_t size, |
| |
793 size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context); |
| |
794 |
| 710 /** |
795 /** |
| 711 * Swaps two array elements. |
796 * Swaps two array elements. |
| 712 * |
797 * |
| 713 * @param arr the array |
798 * @param arr the array |
| 714 * @param elem_size the element size |
799 * @param elem_size the element size |