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

Function algorithm_is_permutation

algorithm/algorithm.c:1888–1933  ·  view source on GitHub ↗

* @brief Checks if two arrays are permutations of each other. * * This function checks whether the elements of the two arrays `base1` and `base2` are permutations of each other. * It does so by ensuring that each element in `base1` has a corresponding element in `base2` and vice versa, * with all elements being matched exactly once. * * @param base1 Pointer to the first array. * @param nu

Source from the content-addressed store, hash-verified

1886 ALGORITHM_LOG("[algorithm_transform] Info: Transforming element at index %zu.", i);
1887 op(output_ptr + i * size, input_ptr + i * size);
1888 }
1889
1890 ALGORITHM_LOG("[algorithm_transform] Success: Transformation completed.");
1891}
1892
1893
1894/**
1895 * @brief Reduces a range of elements to a single value using a specified binary operation.
1896 *
1897 * This function applies the binary operation `op` to each element in the range `[base, base + num * size)`
1898 * and accumulates the result, starting with the initial value `init`.
1899 *
1900 * @param base Pointer to the start of the array.
1901 * @param num Number of elements in the array.
1902 * @param size Size of each element in bytes.
1903 * @param init Pointer to the initial value, which is also used to store the accumulated result.
1904 * @param op Binary operation function that takes two arguments: the accumulated result and the current element.
1905 *
1906 * @return Pointer to the accumulated result (same as `init`).
1907 */
1908void *algorithm_reduce(const void *base, size_t num, size_t size, void *init, ReduceFunc op) {
1909 ALGORITHM_LOG("[algorithm_reduce] Info: Reducing array of %zu elements.", num);
1910
1911 const char *ptr = (const char *)base;
1912 char *result = (char *)init;
1913
1914 for (size_t i = 0; i < num; ++i) {
1915 ALGORITHM_LOG("[algorithm_reduce] Info: Reducing element at index %zu.", i);
1916 op(result, ptr + i * size);
1917 }
1918
1919 ALGORITHM_LOG("[algorithm_reduce] Success: Reduction completed.");
1920 return result;
1921}
1922
1923
1924/**
1925 * @brief Removes consecutive duplicate elements from a sorted array.
1926 *
1927 * This function removes consecutive duplicate elements from a sorted array `base` as determined
1928 * by the comparison function `comp`. The array must be sorted before calling this function.
1929 *
1930 * @param base Pointer to the start of the array.
1931 * @param num Number of elements in the array.
1932 * @param size Size of each element in bytes.
1933 * @param comp Comparison function used to compare elements.
1934 * It should return a negative value if the first element is less than the second,
1935 * zero if they are equal, and a positive value if the first element is greater than the second.
1936 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected