-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodepool.h
98 lines (78 loc) · 1.83 KB
/
nodepool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef _NODEPOOL_H
#define _NODEPOOL_H
#include "runepool.h"
#include "HashTable.h"
#include <vector>
#include <string>
using namespace std;
//最大一个词的长度
#define MAX_WORD_LENGTH 30
//节点类型不同的定义
#define MAIN_DICT_MAP_COUNT 10000
#define CHILD_DICT_MAP_COUNT 50
#define END_DICT_MAP_COUNT 5
//永久节点模型
struct _RuneLinkNode
{
CHashTable m_hmapRuneNextMap;
_Rune m_objRune;
char m_pWord[MAX_WORD_LENGTH];
int m_nPoolIndex;
char m_cUsed; //0为未使用,1为使用
_RuneLinkNode()
{
m_cUsed = 0;
m_nPoolIndex = 0;
memset(m_pWord, 0, MAX_WORD_LENGTH);
}
void Init(char* pData, int nMapSize, char* pcryptTable)
{
m_cUsed = 0;
m_nPoolIndex = 0;
memset(m_pWord, 0, MAX_WORD_LENGTH);
m_hmapRuneNextMap.Init(pData, nMapSize, pcryptTable);
}
void Load(char* pData, int nMapSize, char* pcryptTable)
{
m_hmapRuneNextMap.Load(pData, nMapSize, pcryptTable);
}
void Set_Index(int nIndex)
{
m_nPoolIndex = nIndex;
}
int Get_Index()
{
return m_nPoolIndex;
}
void Set_Used(char cUsed)
{
m_cUsed = cUsed;
}
char Get_Used()
{
return m_cUsed;
}
};
class CNodePool
{
public:
CNodePool();
~CNodePool();
size_t Init(int nPoolCount, char* pData);
size_t Load(int nPoolCount, char* pData);
void Close();
_RuneLinkNode* CreateRoot();
_RuneLinkNode* Create(int nLayer);
int Get_Node_Offset(_RuneLinkNode* pRuneLinkNode);
_RuneLinkNode* Get_NodeOffset_Ptr(int nOffset);
bool Delete(_RuneLinkNode* pNode);
private:
void prepareCryptTable();
private:
char* m_pCryptTable;
char* m_pBase; //整个内存开始地址
int m_nPoolCount;
int m_nCurrIndex;
_RuneLinkNode* m_NodePoolList; //主节点和中间节点列表
};
#endif