📄 leath.cpp
字号:
//#include "StdAfx.h"
#include "WordFilter.h"
#include "BlackList.h"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
int WordFilter(void);
int BlackList(void);
static struct timeval _tstart, _tend;
static struct timezone tz;
void tstart(void);
void tend(void);
double tval(void);
int main(int agrc, char *argv[])
{
BlackList();
WordFilter();
return 0;
}
int BlackList(void)
{
cout << "\n===================\nTEST THE BLACK LIST\n=====================" <<endl;
char cBuf[256];
char cFile[56];
double dDelay = 0;
memset(&cFile, 0, sizeof(cFile));
CBlackList mBL;
cout << "please input file:";
cin >> cFile;
/*
mBL.SetSrcFile((char *)&cFile);
if (mBL.InitList() != 0)
{
cout << "init error!" << endl;
return -1;
}
if (!mBL.CreateHashTable())
{
cout << "Create Hash Table error!" << endl;
return -1;
}
*/
tstart();
if (mBL.InitBlackList((char *)&cFile) != 0)
{
cout << "InitBlackList() error!" << endl;
return -1;
}
tend();
dDelay = tval();
cout << "Create Hash Table delay time: " << dDelay << endl;
unsigned long nMobile = 0;
while (true)
{
memset(&cBuf, 0, sizeof(cBuf));
cout << "please input mobile:";
cin >> cBuf;
//sprintf((char *)&cBuf, "13%9u", (nMobile+507760000));
//nMobile++;
int nLen = strlen(cBuf);
if (strncmp((char *)&cBuf, "quit", 4) == 0)
break;
tstart();
if (mBL.LocateData((char *)&cBuf, nLen))
cout << "===========================================EXIST:" << cBuf << endl;
else
cout << "-------------------------------------------NO EXIST:" << cBuf << endl;
tend();
dDelay = tval();
cout << "locate delay time: " << dDelay << endl;
}
return 0;
}
int WordFilter(void)
{
cout << "\n=======================\nTEST THE FILTER WORLD\n============================" <<endl;
char cBuf[256];
char cFile[56];
double dDelay = 0;
memset(&cFile, 0, sizeof(cFile));
CWordFilter mWF;
cout << "please input file:";
cin >> cFile;
/*
mWF.SetSrcFile((char *)&cFile);
if (mWF.InitWordList() != 0)
{
cout << "init error!" << endl;
return -1;
}
if (!mWF.CreateWordTable())
{
cout << "Create Word Table error!" << endl;
return -1;
}
*/
tstart();
if (mWF.InitWordFilter((char *)&cFile) != 0)
{
cout << "InitWordFilter() error!" << endl;
return -1;
}
tend();
dDelay = tval();
cout << "Create Word Table delay time: " << dDelay << endl;
int n=0;
while (true)
{
memset(&cBuf, 0, sizeof(cBuf));
cout << "please input content:";
cin >> cBuf;
if (n == 0)
{
// strcpy((char *)&cBuf, "过滤测试,本语句要含有要求过滤的敏感词句,它就是jzm这几个英方字母");
n = 1;
}
else
{
// strcpy((char *)&cBuf, "过滤测试,本语句要含有要求过滤的敏感词句,它就是这几个英方字母");
n = 0;
}
int nLen = strlen(cBuf);
if (strncmp((char *)&cBuf, "quit", 4) == 0)
break;
tstart();
if (mWF.LocateFilterWord((const char *)&cBuf, nLen))
cout << "====================NEED:" << cBuf << endl;
else
cout << "-----------------NO NEED:" << cBuf << endl;
tend();
dDelay = tval();
cout << "compare delay time: " << dDelay << endl;
}
return 0;
}
void tstart(void)
{
gettimeofday(&_tstart, &tz);
}
void tend(void)
{
gettimeofday(&_tend,&tz);
}
double tval(void)
{
double t1, t2;
t1 = (double)_tstart.tv_sec + (double)_tstart.tv_usec/(1000*1000);
t2 = (double)_tend.tv_sec + (double)_tend.tv_usec/(1000*1000);
return t2-t1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -