51 lines
1.6 KiB
C
51 lines
1.6 KiB
C
#ifndef INCLUDED_C_BOYERMOORE_H
|
|||
|
|
#define INCLUDED_C_BOYERMOORE_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*/
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
#define C_BM_R 256
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
int R;
|
||
|
|
c_int_t * right;
|
||
|
|
char* pattern;
|
||
|
|
c_size_t pattern_size;
|
||
|
|
c_Allocator_t allocator; // 统一的内联组合分配器实例
|
||
|
|
} c_BoyerMoore_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_BoyerMoore_Init(c_BoyerMoore_t* self, const char* pattern, c_size_t pattern_size, int R, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
void c_BoyerMoore_Destroy(c_BoyerMoore_t* self);
|
||
|
|
|
||
|
|
c_err_t c_BoyerMoore_Search(c_BoyerMoore_t* self, const char* text, c_size_t text_size, c_size_t* index);
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_err_t c_BoyerMoore_InitStr(c_BoyerMoore_t* self, const char* pattern, c_Allocator_t* allocator) {
|
||
|
|
if (!self || !pattern) return C_ERR_PARAM;
|
||
|
|
return c_BoyerMoore_Init(self, pattern, strlen(pattern), 256, allocator);
|
||
|
|
}
|
||
|
|
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_err_t c_BoyerMoore_SearchStr(c_BoyerMoore_t* self, const char* text, c_size_t* index) {
|
||
|
|
if (!self || !text) return C_ERR_PARAM;
|
||
|
|
return c_BoyerMoore_Search(self, text, strlen(text), index);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_BOYERMOORE_H*/
|