MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / algorithm_adjacent_find

Function algorithm_adjacent_find

algorithm/algorithm.c:1800–1819  ·  view source on GitHub ↗

* @brief Finds the first occurrence of two consecutive elements that are equal. * * This function searches through the array pointed to by `base` and finds the first pair of consecutive * elements that are equal, as determined by the comparison function `comp`. * * @param base Pointer to the start of the array. * @param num Number of elements in the array. * @param size Size of each elemen

Source from the content-addressed store, hash-verified

1798 }
1799 b += (comp(b, val) < 0) ? size : 0;
1800 return (void *)b;
1801 }
1802 size_t low = 0;
1803 size_t high = num;
1804 while (low < high) {
1805 size_t mid = low + (high - low) / 2;
1806 if (comp(b + mid * size, val) < 0) {
1807 low = mid + 1;
1808 }
1809 else {
1810 high = mid;
1811 }
1812 }
1813
1814 ALGORITHM_LOG("[algorithm_lower_bound] Success: Found lower bound at index %zu.", low);
1815 return (void *)(b + low * size);
1816}
1817
1818
1819/**
1820 * @brief Finds the first position in a sorted range where a value is greater than a specified value.
1821 *
1822 * This function performs a binary search on a sorted range `[base, base + num * size)` to find the first

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected