* @brief Searches for the first occurrence of a sequence within another sequence. * * This function searches for the first occurrence of the sequence starting at `first2` and ending at `last2` * within the sequence starting at `first1` and ending at `last1`. * * @param first1 Pointer to the start of the first sequence. * @param last1 Pointer to the end of the first sequence. * @param size1
| 1950 | for (size_t i = 1; i < num; ++i) { |
| 1951 | if (comp(array + (uniqueCount - 1) * size, array + i * size) != 0) { |
| 1952 | if (uniqueCount != i) { |
| 1953 | alg_copy_elem(array + uniqueCount * size, array + i * size, size); |
| 1954 | ALGORITHM_LOG("[algorithm_unique] Info: Moving element at index %zu to position %zu.", i, uniqueCount); |
| 1955 | } |
| 1956 | uniqueCount++; |
| 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | ALGORITHM_LOG("[algorithm_unique] Success: Number of unique elements is %zu.", uniqueCount); |
| 1961 | return uniqueCount; |
| 1962 | } |
| 1963 | |
| 1964 | |
| 1965 | /** |
| 1966 | * @brief Checks if two ranges are equal. |
| 1967 | * |
| 1968 | * This function compares two ranges `[base1, base1 + num1 * size1)` and `[base2, base2 + num2 * size2)` |
| 1969 | * to determine if they contain the same elements in the same order, as determined by the comparison function `comp`. |
| 1970 | * |
| 1971 | * @param base1 Pointer to the start of the first array. |
| 1972 | * @param num1 Number of elements in the first array. |
| 1973 | * @param size1 Size of each element in the first array in bytes. |
| 1974 | * @param base2 Pointer to the start of the second array. |
| 1975 | * @param num2 Number of elements in the second array. |
| 1976 | * @param size2 Size of each element in the second array in bytes. |
| 1977 | * @param comp Comparison function used to compare elements.It should return 0 if the elements are equal, and a non-zero value otherwise. |
| 1978 | * |
| 1979 | * @return `true` if the two ranges are equal, `false` otherwise. |
| 1980 | */ |
| 1981 | bool algorithm_equal(const void *base1, size_t num1, size_t size1, const void *base2, size_t num2, size_t size2, CompareFunc comp) { |
| 1982 | ALGORITHM_LOG("[algorithm_equal] Info: Comparing two arrays of %zu and %zu elements.", num1, num2); |
| 1983 | if (num1 != num2 || size1 != size2) { |
| 1984 | ALGORITHM_LOG("[algorithm_equal] Warning: Arrays have different sizes, returning false."); |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
| 1988 | const char *ptr1 = (const char *)base1; |
| 1989 | const char *ptr2 = (const char *)base2; |
nothing calls this directly
no outgoing calls
no test coverage detected