This commit is contained in:
wyy 2013-06-24 16:20:10 +08:00
parent 5be8d48a18
commit 651800d07e
2 changed files with 12 additions and 16 deletions

View File

@ -22,7 +22,6 @@ namespace CppJieba
return false;
}
_root = new TrieNode;
_root->isLeaf = false;
ifstream ifile(filepath);
string line;
vector<string> vecBuf;
@ -36,20 +35,11 @@ namespace CppJieba
LogError(msgBuf);
return false;
}
//PRINT_VECTOR(vecBuf);
//getchar();
string chWord = vecBuf[0];
unsigned int count = atoi(vecBuf[1].c_str());
const string& tag = vecBuf[2];
size_t uniLen = utf8ToUnicode(chWord.c_str(), chWord.size(), chUniBuf);
_insert(chUniBuf, uniLen);
//for(int i = 0; i < unilen; i++)
//{
// // printf("%x\n", strbuf[i]);
//}
//char utf8str[512]={0};
//unicodeToUtf8(strbuf, unilen, utf8str);
//cout<<strlen(utf8str);
//cout<<utf8str<<endl;
_insert(chUniBuf, uniLen, count, tag);
}
return true;
}
@ -145,7 +135,7 @@ namespace CppJieba
}
}
bool Trie::_insert(const ChUnicode* chUniStr, size_t len)
bool Trie::_insert(const ChUnicode* chUniStr, size_t len, unsigned int cnt, const string& tag)
{
if(0 == len)
{
@ -159,7 +149,6 @@ namespace CppJieba
if(p->hmap.end() == p->hmap.find(cu))
{
TrieNode * next = new TrieNode;
next->isLeaf = false;
p->hmap[cu] = next;
p = next;
}

9
Trie.h
View File

@ -22,6 +22,13 @@ namespace CppJieba
{
TrieNodeHashMap hmap;
bool isLeaf;
unsigned int count;
string tag;
TrieNode()
{
isLeaf = false;
count = 0;
}
};
class Trie
@ -39,7 +46,7 @@ namespace CppJieba
private:
bool _destroyNode(TrieNode* node);
void _display(TrieNode* node, int level);
bool _insert(const ChUnicode* chUniBuf, size_t len);
bool _insert(const ChUnicode* chUniBuf, size_t len, unsigned int cnt, const string& tag);
};
}