资源简介
该代码是WM算法和示例,感兴趣的小伙伴可以下载研究一下
代码片段和文件信息
/*
* WM.cpp
*
* Created on: 2010-2-20
* Author: qingxuan.chenqx
*/
#include
#include
#include
#include
#include “wm.h“
extern int nline = 1;
extern int nfound = 0;
#define MAXN 10001 //模式串的最大长度MAXN - 1
#define MAXM 51//单词最大长度为MAXM - 1
WM_STRUCT * wmNew()
{
WM_STRUCT *p = (WM_STRUCT *) malloc(sizeof(WM_STRUCT));
if (!p)
return 0;
p->msNumPatterns = 0;
p->msSmallest = 1000;
return p;
}
void wmFree(WM_STRUCT *ps)
{
if (ps->msPatArray)
{
if (ps->msPatArray->psPat)
free(ps->msPatArray->psPat);
free(ps->msPatArray);
}
if (ps->msNumArray)
free(ps->msNumArray);
if (ps->msHash)
free(ps->msHash);
if (ps->msPrefix)
free(ps->msPrefix);
if (ps->msShift)
free(ps->msShift);
free(ps);
}
int wmAddPattern(WM_STRUCT *ps unsigned char *q int m)//m字符串长度
{
WM_PATTERN_STRUCT *p;
p = (WM_PATTERN_STRUCT *) malloc(sizeof(WM_PATTERN_STRUCT));
if (!p)
return -1;
p->psPat = (unsigned char*) malloc(m + 1);
memset(p->psPat + m 0 1);
memcpy(p->psPat q m);
p->psLen = m;
ps->msNumPatterns++;
if (p->psLen < (unsigned) ps->msSmallest)
ps->msSmallest = p->psLen;
p->next = ps->plist;
ps->plist = p;
return 0;
}
static unsigned HASH16(unsigned char *T)
{
return (unsigned short) (((*T) << 8) | *(T + 1));
}
void sort(WM_STRUCT *ps)//字符串哈希值从小到大排列
{
int m = ps->msSmallest;
int i j;
unsigned char *temp;
int flag;
for (i = ps->msNumPatterns - 1 flag = 1; i > 0 && flag; i--)
{
flag = 0;
for (j = 0; j < i; j++)
{
if (HASH16(&(ps->msPatArray[j + 1].psPat[m - 2])) < HASH16(
&(ps->msPatArray[j].psPat[m - 2])))
{
flag = 1;
temp = ps->msPatArray[j + 1].psPat;
ps->msPatArray[j + 1].psPat = ps->msPatArray[j].psPat;
ps->msPatArray[j].psPat = temp;
}
}
}
}
static void wmPrepHashedPatternGroups(WM_STRUCT *ps)//计算有多少个不同哈希值,且从小到大
{
unsigned sindex hindex ningroup;
int i;
int m = ps->msSmallest;
ps->msNumHashEntries = HASHTABLESIZE;
ps->msHash = (HASH_TYPE*) malloc(sizeof(HASH_TYPE) * ps->msNumHashEntries);
if (!ps->msHash)
{
printf(“No memory in wmPrepHashedPatternGroups()\n“);
return;
}
for (i = 0; i < (int) ps->msNumHashEntries; i++)
{
ps->msHash[i] = (HASH_TYPE) -1;
}
for (i = 0; i < ps->msNumPatterns; i++)
{
hindex = HASH16(&ps->msPatArray[i].psPat[m - 2]);
sindex = ps->msHash[hindex] = i;
ningroup = 1;
while ((++i < ps->msNumPatterns) && (hindex == HASH16(
&ps->msPatArray[i].psPat[m - 2])))
ningroup++;
ps->msNumArray[sindex] = ningroup;
i--;
}
}
static void wmPrepShiftTable(WM_STRUCT *ps)//建立shift表
{
int i;
unsigned short m k cindex;
unsigned shift;
m = (unsigned short) ps->msSmallest;
ps->msShift = (unsigned char*) malloc(SHIFTTABLESIZE * sizeof(char));
if (!ps->msShift)
return;
for (i = 0; i < SHIFTTABLESIZE; i++)
{
ps->msShift[i] = (unsigned) (m - 2 + 1);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6363 2017-01-11 14:20 WM多模算法(C)\WM.cpp
文件 1218 2017-01-11 14:20 WM多模算法(C)\WM.h
目录 0 2018-09-29 15:40 WM多模算法(C)
----------- --------- ---------- ----- ----
7581 3
- 上一篇:通过查看二进制文件判断文件类型
- 下一篇:mv9713.pdf
相关资源
- FPGA\\基于FPGA的温度检测和PWM风冷系统
- 单片机产生SPWM设计报告
- silicon 单片机 PWM 马达控制
- CWM元模型研究及其在广发银行数据仓
- 基于STM32 控制电机程序
- STM8S_PWM_LED呼吸灯
- STM32_PWM 呼吸灯 MDK 源代码
- 基于FPGA的多路PWM发生器设计
- wm8960 音频播放
- 基于attiny13的pwm和ad采样程序
- opencv检查图片中是否有人
- 基于DSP的PWM波生成例程
-
PotPla
yer播放器wmp12风格皮肤 - RMS_CHS_WM2003sp_WM5_0_V2.0.exe
- DSPF28335带死区设置的SPWM代码
- 利用adc0808出pwm程序
- 基于STM32的SPWM波产生程序
- Leaflet.js加载天地图的WMTS服务EPSG4326类
- c8051f系列单片机PCA实现PWM波输出
- 51单片机SPWM输出程序
- 基于51单片机的PWM直流电机调速prote
- C经典教材-C和指针课后习题答案
- 智能WCS系统介绍
- CppLesson070AddNewMap.zip
- servo_foc
- Nokia Mobile Browser Simulator 4.0(手机模拟
- ESP8266 PWM源文件
- STM32F103C8T6 PWM控制SG90舵机
- 采用不对称采样计算SPWM波生成
- 对称规则采样SPWM波计算图文讲解
评论
共有 条评论