* @brief Rotates elements in a range and copies them to a destination array. * * @param first Pointer to the start of the range. * @param middle Pointer to the middle of the range. * @param last Pointer to the end of the range. * @param size Size of each element in bytes. * @param result Pointer to the destination array. */
| 1670 | |
| 1671 | /** |
| 1672 | * @brief Counts the number of occurrences of a value in a range. |
| 1673 | * |
| 1674 | * This function iterates over the elements in the range `[base, base + num * size)` and counts |
| 1675 | * how many times the value `val` appears, as determined by the comparison function `comp`. |
| 1676 | * |
| 1677 | * @param base Pointer to the start of the array. |
| 1678 | * @param num Number of elements in the array. |
| 1679 | * @param size Size of each element in bytes. |
| 1680 | * @param val Pointer to the value to be counted. |
| 1681 | * @param comp Comparison function used to compare elements. |
| 1682 | * It should return 0 if the elements are equal, and a non-zero value otherwise. |
| 1683 | * |
| 1684 | * @return The number of times `val` appears in the range. |
| 1685 | */ |
| 1686 | size_t algorithm_count(const void *base, size_t num, size_t size, const void *val, CompareFunc comp) { |
| 1687 | ALGORITHM_LOG("[algorithm_count] Info: Counting occurrences of value in array of %zu elements.", num); |
| 1688 | |
| 1689 | size_t count = 0; |
| 1690 | const char *ptr = (const char *)base; |
| 1691 | |
| 1692 | for (size_t i = 0; i < num; ++i) { |
| 1693 | if (comp(ptr + i * size, val) == 0) { |
| 1694 | ++count; |
| 1695 | ALGORITHM_LOG("[algorithm_count] Info: Found match at index %zu.", i); |
nothing calls this directly
no outgoing calls
no test coverage detected