You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.9 KiB
C++

#pragma once
#include <string>
#include "CDBF.H"
#include "mySqlite.h"
#include "global.h"
using namespace std;
#define HASH_COUNT_MAX 50*1024 //
#define HASH_COUNT_PERCENT 100 //hash值比例
#define FILE_COPY_BUFFER_LEN (2*1024*1024)
#define HASH_BUFFER_RECCOUNT_PERBLOCK (128*1024) //一次分配256*1024*sizeof(HashNode)=2M
#define DB_TYPE_DBF 1
#define DB_TYPE_SQLITE 2
#pragma pack(push) //保存对齐状态
#pragma pack(1) // 1 bytes对齐
typedef struct tagHashNode {
unsigned short nHashValue;
//unsigned int nRecordNo;
tagHashNode *pNext;
}HashNode;
typedef struct {
unsigned short nNodeCount;
HashNode *pNode;
}HashHead;
#pragma pack(pop)
typedef struct {
HANDLE hMsgWnd;
unsigned int iMsgValue;
char MainDBFFileName[MAX_PATH + 1];
char SlaveDBFFileName[MAX_PATH + 1];
char strKeyFieldName[MAX_PATH + 1];
unsigned int iListId;
HANDLE hThread;
DWORD dwThreadId;
bool bThreadExit;
}THREADPARAMS;
typedef HashNode ** PNodeArray;
typedef struct {
CDBF *pDBF;
mySqlite * pSqlite;
// unsigned int type;
unsigned int nHeadBlockCount; //hash头数组分块数
unsigned int nHeadCount; //hash头数组元素总数
PNodeArray pHead; //邻接表 HashHead
unsigned int nNodeBlockCount; //节点内存分块数
unsigned int nNodeCount; //节点数,实际等于记录数
unsigned int nNodeUsed; //已使用节点
PNodeArray pNode; //二位节点指针数组 HashNode
}HASH_LIST;
typedef struct {
long nRecordNo[255];
}RECORDNO_ARRAY;
class CBlackList
{
private:
//char FileCopyBuffer[FILE_COPY_BUFFER_LEN];
CRITICAL_SECTION csFind;
CRITICAL_SECTION cs;
int iKeyFieldIndex;
HASH_LIST HashListMain;
HASH_LIST HashListSlave;
//czw 添加
PFN_OpenThread m_OpenThreadPtr;
int m_HashListType;
string m_PriKey;
string m_DbfName;
public:
THREADPARAMS threadParams;
private:
void FreeHashList(HASH_LIST &hashList);
int Open(HASH_LIST &hashList, const char *BlackFileName, const char *strKeyField);
unsigned int HashA(const char *lpszString, const int len);
unsigned int HashB(const char *lpszString, const int len);
unsigned int HashString(const char *lpszString, const int dwHashType);
bool MPQHashBuffAlloc(const int recordCount, HASH_LIST &hashList);
void MPQHashTableAdd(HASH_LIST &hashList, const char *lpszString,const unsigned int nRecordNo);
bool BuffAlloc(PNodeArray &pBlock, unsigned int &nAllocCount, const int nCount, const int iBlockCount,const int sizeBlock);
RECORDNO_ARRAY MPQHashTableIsExist(HASH_LIST &hashList, const char *lpszString, bool bFindAll);
bool BackThreadIsActive();
int GetRecordNo(HashNode *pNode);
//czw添加
int GetDbType(const char *BlackFileName);
bool OpenDbf(HASH_LIST &hashList, const char *BlackFileName, const char *strKeyField);
bool OpenSqlite(HASH_LIST &hashList, const char *BlackFileName, const char *strKeyField);
string FindDbf(const char *KeyValue, bool &bFound, const bool bFindAll);
string FindDSqlite(const char *KeyValue, bool &bFound, const bool bFindAll);
string GetVerInfoDbf(const char *VerFieldName, int &RecordCount);
string GetVerInfoSqlite(const char *VerFieldName, int &RecordCount);
public:
CBlackList();
~CBlackList();
bool Load(const char *BlackFileName, const char *strKeyField);
int LoadListBack(HANDLE hMsgWnd, unsigned int iMsgValue, unsigned int iListId,
char* MainDBFFileName, char *SlaveDBFFileName, char* strKeyFieldName);
bool doLoadListBack(const unsigned int iListID, const char *MainBlackFilePath, const char *BlackFileName, const char *strKeyField);
int BackOnline(const char *MainBlackFileName, const char *SlaveBlackFileName);
string Find(const char *KeyValue, bool &bFound, const bool bFindAll);
string FinDSqWhere(const char *pwhere, bool &bFound);
string GetVerInfo(const char *VerFieldName, int &RecordCount);
//czw 添加
void SetOpenThreadPtr(PFN_OpenThread ptr);
string GetPriKeyName();
string GetDbfFileName();
};