* @brief Finds the first position where two ranges differ. * * This function compares two arrays element by element and returns the first position where the elements differ. * The comparison is done using the comparison function `comp`. * * @param base1 Pointer to the start of the first array. * @param num1 Number of elements in the first array. * @param size1 Size of each element in the fi
| 1841 | } |
| 1842 | if (num > ALG_BSEARCH_PREFETCH_BYTES / size) { |
| 1843 | while (num > 1) { |
| 1844 | size_t half = num / 2; |
| 1845 | ALG_PREFETCH(b + (half / 2) * size); |
| 1846 | ALG_PREFETCH(b + (half + half / 2) * size); |
| 1847 | b = (comp(b + half * size, val) <= 0) ? b + half * size : b; |
| 1848 | num -= half; |
| 1849 | } |
| 1850 | b += (comp(b, val) <= 0) ? size : 0; |
| 1851 | return (void *)b; |
| 1852 | } |
| 1853 | size_t low = 0; |
| 1854 | size_t high = num; |
| 1855 | while (low < high) { |
| 1856 | size_t mid = low + (high - low) / 2; |
| 1857 | if (comp(b + mid * size, val) <= 0) { |
| 1858 | low = mid + 1; |
| 1859 | } |
| 1860 | else { |
| 1861 | high = mid; |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | ALGORITHM_LOG("[algorithm_upper_bound] Success: Found upper bound at index %zu.", low); |
| 1866 | return (void *)(b + low * size); |
| 1867 | } |
| 1868 | |
| 1869 | |
| 1870 | /** |
| 1871 | * @brief Transforms each element in an array and stores the result in another array. |
nothing calls this directly
no outgoing calls
no test coverage detected