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

Function algorithm_is_sorted_until

algorithm/algorithm.c:1614–1631  ·  view source on GitHub ↗

* @brief Finds the first position in a range where the elements are no longer sorted. * * This function searches through the array pointed to by `base` and finds the first element * where the sequence is no longer 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. *

Source from the content-addressed store, hash-verified

1612 if (count == 0) {
1613 return;
1614 }
1615 const char *v = (const char *)val;
1616 if (v + size > dst && v < dst + count * size) { /* val inside the range: copy it aside */
1617 AlgScratch stk;
1618 char *copy = (size <= sizeof stk.bytes) ? (char *)stk.bytes : (char *)malloc(size);
1619 if (!copy) {
1620 for (size_t i = 0; i < count; ++i) { /* rare: large element, no memory */
1621 if (dst + i * size != v) {
1622 memmove(dst + i * size, v, size);
1623 }
1624 }
1625 return;
1626 }
1627 memcpy(copy, v, size);
1628 alg_fill_bytes(dst, copy, size, count);
1629 if (copy != (char *)stk.bytes) {
1630 free(copy);
1631 }
1632 return;
1633 }
1634 alg_fill_bytes(dst, val, size, count);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected