36 lines
1.4 KiB
C
36 lines
1.4 KiB
C
#ifndef INCLUDED_C_RABINKARP_H
|
|||
|
|
#define INCLUDED_C_RABINKARP_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_TYPES_H
|
||
|
|
#include <c_Types.h>
|
||
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
||
|
|
#include <c_Allocator.h>
|
||
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
||
|
|
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
char* pattern; // 独立深拷贝转储的模式串(子串)载体
|
||
|
|
c_size_t m_len; // 模式串的有效字符物理长度 (M)
|
||
|
|
uint64_t pattern_hash; // 模式串的数字指纹哈希码值
|
||
|
|
uint64_t RM; // 滚动哈希最高位字符的位移系数权重乘子: R^(M-1) % Q
|
||
|
|
uint64_t Q_prime; // 滚动哈希专用的大素数取模基数 (Q)
|
||
|
|
uint64_t R_base; // 字母表物理基数 (常数项乘子,扩展 ASCII 固定为 256)
|
||
|
|
c_Allocator_t allocator; // 统一的内联组合分配器实例
|
||
|
|
} c_RabinKarp_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_RabinKarp_Init(c_RabinKarp_t* self, const char* pattern, c_Allocator_t* allocator);
|
||
|
|
c_err_t c_RabinKarp_Search(const c_RabinKarp_t* self, const char* text, c_size_t* out_index);
|
||
|
|
void c_RabinKarp_Destroy(c_RabinKarp_t* self);
|
||
|
|
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_RABINKARP_H*/
|