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

Function algorithm_unique_copy

algorithm/algorithm.c:1456–1479  ·  view source on GitHub ↗

* @brief Copies unique elements from a sorted range to a new range. * * This function copies unique elements from the sorted array `first` to the array `result`, * as determined by the comparison function `comp`. Elements that are equal (according to `comp`) * are only copied once. * * @param first Pointer to the start of the sorted array. * @param num Number of elements in the source array

Source from the content-addressed store, hash-verified

1454
1455 char *ptr = (char *)base;
1456 for (size_t i = 0; i < num; ++i) {
1457 op(ptr + i * size);
1458 }
1459
1460 ALGORITHM_LOG("[algorithm_for_each] Success: Operation applied to all elements.");
1461}
1462
1463
1464/**
1465 * @brief Copies elements from a source array to a destination array.
1466 *
1467 * @param source Pointer to the source array.
1468 * @param num Number of elements to copy.
1469 * @param size Size of each element in bytes.
1470 * @param dest Pointer to the destination array.
1471 */
1472void algorithm_copy(const void *source, size_t num, size_t size, void *dest) {
1473 ALGORITHM_LOG("[algorithm_copy] Info: Copying %zu elements.", num);
1474
1475 if (!source || !dest || num == 0 || size == 0) {
1476 return;
1477 }
1478 /* one block copy; memmove keeps overlapping ranges correct */
1479 memmove(dest, source, num * size);
1480
1481 ALGORITHM_LOG("[algorithm_copy] Success: Copy completed.");
1482}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected