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

Function algorithm_max_element

algorithm/algorithm.c:521–539  ·  view source on GitHub ↗

* @brief Finds the maximum element in a range. * * This function iterates over the elements in the range `[base, base + num * size)` to find the maximum * element, as determined 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. * @param comp Comparison function use

Source from the content-addressed store, hash-verified

519 size_t lsplit = (numl == 0) ? ((numr == 0) ? unknown / 2 : unknown) : 0;
520 size_t rsplit = (numr == 0) ? (unknown - lsplit) : 0;
521 if (lsplit > PDQ_BLOCK) {
522 lsplit = PDQ_BLOCK;
523 }
524 if (rsplit > PDQ_BLOCK) {
525 rsplit = PDQ_BLOCK;
526 }
527 for (size_t i = 0; i < lsplit; ++i) {
528 offl[numl] = (unsigned char)i;
529 numl += !(comp(a + f * sz, p) < 0);
530 ++f;
531 }
532 for (size_t i = 0; i < rsplit; ) {
533 offr[numr] = (unsigned char)++i;
534 numr += comp(a + (--l) * sz, p) < 0;
535 }
536 size_t num = numl < numr ? numl : numr;
537 if (num) {
538 if (numl == numr) {
539 for (size_t i = 0; i < num; ++i) {
540 alg_swap_bytes(a + (basel + offl[startl + i]) * sz, a + (baser - offr[startr + i]) * sz, sz);
541 }
542 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected