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

Function algorithm_is_sorted

algorithm/algorithm.c:1576–1594  ·  view source on GitHub ↗

* @brief Checks if the elements in a range are sorted in non-decreasing order. * * This function determines whether the elements in the array pointed to by `base` are sorted * in non-decreasing order, as defined 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 element in bytes. * @

Source from the content-addressed store, hash-verified

1574 * @brief Checks if none of the elements in a range satisfy a predicate.
1575 *
1576 * This function returns `true` if the predicate `pred` returns `false` for all elements in the range
1577 * `[base, base + num * size)`. Otherwise, it returns `false`.
1578 *
1579 * @param base Pointer to the start of the array.
1580 * @param num Number of elements in the array.
1581 * @param size Size of each element in bytes.
1582 * @param pred Predicate function to check each element.
1583 *
1584 * @return `true` if none of the elements satisfy the predicate, `false` otherwise.
1585 */
1586bool algorithm_none_of(const void *base, size_t num, size_t size, BoolPredicateFunc pred) {
1587 ALGORITHM_LOG("[algorithm_none_of] Info: Checking if none of the elements of %zu satisfy the predicate.", num);
1588
1589 const char *ptr = (const char *)base;
1590 for (size_t i = 0; i < num; ++i) {
1591 if (pred(ptr + i * size)) {
1592 ALGORITHM_LOG("[algorithm_none_of] Info: Element at index %zu satisfies the predicate, returning false.", i);
1593 return false;
1594 }
1595 }
1596
1597 ALGORITHM_LOG("[algorithm_none_of] Success: None of the elements satisfy the predicate.");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected