字符串匹配之Shift And算法
来源:互联网 发布:jdbc示例数据库 编辑:程序博客网 时间:2024/05/29 14:36
基于前缀的搜索——详情参阅《柔性字符串匹配》这本好书,别的就不多说了
直接给出我的实现...
- template <class Output_Function>
- size_t Shift_And(const char* source,const char* to_find,Output_Function out){
- /**
- * 在source中查找to_find,利用out输出每次出现的地方
- * 返回to_find在source中出现的次数
- */
- size_t n=strlen(source),m=strlen(to_find);
- size_t occured=0;
- if (n<m) return 0;
- const int mask_len=m/64+1;
- const int last_section_len=m%64;
- __int64 mask[128][mask_len]; //GCC support VLA well, Why not use it ?
- for(int i=0;i<mask_len;++i){
- for(int j=0;j<128;++j){
- mask[j][i]=0;
- }
- }
- for(size_t j=0;j<m;++j){
- mask[static_cast<int>(to_find[j])][j/64]|=1<<(j%64);
- }
- __int64 D[mask_len];
- for(int i=0;i<mask_len;++i){
- D[i]=0;
- }
- for(size_t pos=0;pos<n;++pos){
- for(int i=mask_len-1;i>=1;--i){
- D[i]<<=1;
- D[i]|=D[i-1]>>63;
- D[i]&=mask[static_cast<int>(to_find[pos])][i];
- }
- D[0]<<=1;
- D[0]|=1;
- D[0]&=mask[static_cast<int>(source[pos])][0];
- if (D[mask_len-1]>>(last_section_len-1)){
- out(pos-m+1);
- ++occured;
- }
- }
- return occured;
- }
- 字符串匹配之Shift And算法
- 字符串匹配算法-Shift And算法
- 扩展字符串匹配-Shift-And算法扩展
- shift and与shift or字符串匹配算法
- hdu5716 hdu5745 shift-and字符串匹配
- HDU 5972 Regular Number Bitset优化字符串匹配 +Shift-And算法
- shift-And / shift-Or 算法
- 俩个模式匹配算法(BMH and shift-Or)
- 多字符串匹配-multiple shift-and算法
- 字符串匹配之朴素字符串匹配算法
- 字符串匹配算法 之 朴素字符串匹配
- HDU 5972 Regular Number Bitset (字符串匹配shift and/or)
- 字符串匹配之首尾匹配算法
- 字符串匹配之BM算法
- 字符串匹配之Horspool算法
- 字符串匹配之BM算法
- 字符串匹配之KMP算法
- 字符串匹配之朴素算法
- Erlang 的安装配置,编译和运行
- asp.net控件开发基础系列
- My Understanding of MQSeries
- Mathematics English Vocabulary (Cited)
- hibernate get() load() 区别
- 字符串匹配之Shift And算法
- 有关汉字系统的关键技术/纯汇编显示中文/汉字显示/Nasm源码
- C#基础概念二十五问
- 一个CSS+DIV的demo
- 常用eclipse 插件
- 字符串匹配之Horspool算法
- MODEM技术术语解释
- Java Desktop开发资源
- Visual C++ 中stdafx.h