* @brief Merges two sorted arrays into a single sorted array. * * @param base1 Pointer to the first sorted array. * @param num1 Number of elements in the first array. * @param base2 Pointer to the second sorted array. * @param num2 Number of elements in the second array. * @param size Size of each element in bytes. * @param result Pointer to the array where the merged result will be stored.
| 1704 | /** |
| 1705 | * @brief Counts the number of elements in a range that satisfy a predicate function. |
| 1706 | * |
| 1707 | * This function iterates over the elements in the range `[base, base + num * size)` and counts |
| 1708 | * how many of them satisfy the predicate function `pred`. |
| 1709 | * |
| 1710 | * @param base Pointer to the start of the array. |
| 1711 | * @param num Number of elements in the array. |
| 1712 | * @param size Size of each element in bytes. |
| 1713 | * @param pred Predicate function that returns `true` for elements that should be counted. |
| 1714 | * |
| 1715 | * @return The number of elements that satisfy the predicate function `pred`. |
| 1716 | */ |
| 1717 | size_t algorithm_count_if(const void *base, size_t num, size_t size, BoolPredicateFunc pred) { |
| 1718 | ALGORITHM_LOG("[algorithm_count_if] Info: Counting elements that satisfy the predicate in array of %zu elements.", num); |
| 1719 | |
| 1720 | size_t count = 0; |
| 1721 | const char *ptr = (const char *)base; |
| 1722 | for (size_t i = 0; i < num; ++i) { |
| 1723 | if (pred(ptr + i * size)) { |
| 1724 | ++count; |
| 1725 | ALGORITHM_LOG("[algorithm_count_if] Info: Predicate satisfied at index %zu.", i); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | ALGORITHM_LOG("[algorithm_count_if] Success: Total elements that satisfy the predicate: %zu.", count); |
| 1730 | return count; |
| 1731 | } |
| 1732 | |
| 1733 | |
| 1734 | /** |
| 1735 | * @brief Randomly shuffles elements in an array (Fisher-Yates). |
| 1736 | * |
| 1737 | * Every permutation is equally likely, and the same generator gives the same |
| 1738 | * permutation as earlier versions of this function (see alg_random_index). |
| 1739 | * |
| 1740 | * @param base Pointer to the start of the array. |
nothing calls this directly
no outgoing calls
no test coverage detected