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

Function algorithm_includes

algorithm/algorithm.c:1414–1436  ·  view source on GitHub ↗

* @brief Determines if a sorted range includes all the elements of another sorted range. * * This function checks if all elements of the sorted range `[first2, first2 + num2)` are contained * within the sorted range `[first1, first1 + num1)` as determined by the comparison function `comp`. * * @param first1 Pointer to the start of the first sorted array. * @param num1 Number of elements in t

Source from the content-addressed store, hash-verified

1412 * element, as determined by the comparison function `comp`.
1413 *
1414 * @param base Pointer to the start of the array.
1415 * @param num Number of elements in the array.
1416 * @param size Size of each element in bytes.
1417 * @param comp Comparison function used to compare elements.
1418 * It should return a negative value if the first element is less than the second,
1419 * zero if they are equal, and a positive value if the first element is greater than the second.
1420 *
1421 * @return Pointer to the minimum element, or `NULL` if the array is empty.
1422 */
1423void *algorithm_min_element(const void *base, size_t num, size_t size, CompareFunc comp) {
1424 if (num == 0) {
1425 ALGORITHM_LOG("[algorithm_min_element] Error: Array is empty, returning NULL.");
1426 return NULL;
1427 }
1428 ALGORITHM_LOG("[algorithm_min_element] Info: Searching for the minimum element in an array of %zu elements.", num);
1429
1430 const char *min_element = (const char *)base;
1431 for (size_t i = 1; i < num; ++i) {
1432 const char *element = (const char *)base + i * size;
1433 if (comp(min_element, element) > 0) {
1434 min_element = element;
1435 ALGORITHM_LOG("[algorithm_min_element] Info: New minimum element found at index %zu.", i);
1436 }
1437 }
1438
1439 ALGORITHM_LOG("[algorithm_min_element] Success: Minimum element found.");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected