#ifndef INCLUDED_C_LONGESTCOMMONSUBSTRING_H #define INCLUDED_C_LONGESTCOMMONSUBSTRING_H #ifndef INCLUDED_C_TYPES_H #include #endif /*INCLUDED_C_TYPES_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #endif /*INCLUDED_C_ALLOCATOR_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ typedef struct { c_size_t max_len; /* Length of the longest common substring found */ c_size_t start_idx_a; /* Starting coordinate index inside String A sequence */ c_Allocator_t allocator; /* Deep copy of the user-provided allocator */ } c_LongestCommonSubstring_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ /** * @brief Non-recursively computes the longest common substring between String A and String B. * @param str_a Null-terminated or bound-verified character string A sequence * @param str_b Null-terminated or bound-verified character string B sequence * @param allocator Explicit allocator context used to configure temporary dynamic matrices */ c_err_t c_LongestCommonSubstring_Init(c_LongestCommonSubstring_t* self, const char* str_a, const char* str_b, c_Allocator_t* allocator); /** * @brief Releases internal tracking structures safely (Trivial for rolling array layouts). */ void c_LongestCommonSubstring_Destroy(c_LongestCommonSubstring_t* self); /** * @brief Returns the length of the discovered longest common substring. */ C_STATIC_FORCE_INLINE c_size_t c_LongestCommonSubstring_GetLen(const c_LongestCommonSubstring_t* self) { return self ? self->max_len : 0; } /** * @brief Extracts the resolved longest common substring payload back into a safe user buffer. * @param out_buffer Presized destination character array to copy results into * @param buffer_cap Maximum threshold size limit matching out_buffer allocation bounds */ c_err_t c_LongestCommonSubstring_GetSubstring(const c_LongestCommonSubstring_t* self, const char* str_a, char* out_buffer, c_size_t buffer_cap); #endif /*INCLUDED_C_LONGESTCOMMONSUBSTRING_H*/