mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
modify _instertNode
This commit is contained in:
parent
a3e0db22e8
commit
1536a9e2e3
17
src/Trie.hpp
17
src/Trie.hpp
@ -94,12 +94,11 @@ namespace CppJieba
|
|||||||
const TrieNodeInfo* find(Unicode::const_iterator begin, Unicode::const_iterator end)const
|
const TrieNodeInfo* find(Unicode::const_iterator begin, Unicode::const_iterator end)const
|
||||||
{
|
{
|
||||||
TrieNodeMap::const_iterator citer;
|
TrieNodeMap::const_iterator citer;
|
||||||
TrieNode* p = _root;
|
const TrieNode* p = _root;
|
||||||
for(Unicode::const_iterator it = begin; it != end; it++)
|
for(Unicode::const_iterator it = begin; it != end; it++)
|
||||||
{
|
{
|
||||||
uint16_t chUni = *it;
|
citer = p->hmap.find(*it);
|
||||||
citer = p->hmap.find(chUni);
|
if(p->hmap.end() == citer)
|
||||||
if(p-> hmap.end() == citer)
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -114,7 +113,7 @@ namespace CppJieba
|
|||||||
|
|
||||||
bool find(Unicode::const_iterator begin, Unicode::const_iterator end, DagType & res, size_t offset = 0) const
|
bool find(Unicode::const_iterator begin, Unicode::const_iterator end, DagType & res, size_t offset = 0) const
|
||||||
{
|
{
|
||||||
TrieNode* p = _root;
|
const TrieNode* p = _root;
|
||||||
TrieNodeMap::const_iterator citer;
|
TrieNodeMap::const_iterator citer;
|
||||||
for (Unicode::const_iterator itr = begin; itr != end; itr++)
|
for (Unicode::const_iterator itr = begin; itr != end; itr++)
|
||||||
{
|
{
|
||||||
@ -139,21 +138,23 @@ namespace CppJieba
|
|||||||
void _insertNode(const TrieNodeInfo& nodeInfo, TrieNode* ptNode) const
|
void _insertNode(const TrieNodeInfo& nodeInfo, TrieNode* ptNode) const
|
||||||
{
|
{
|
||||||
const Unicode& unico = nodeInfo.word;
|
const Unicode& unico = nodeInfo.word;
|
||||||
|
TrieNodeMap::const_iterator citer;
|
||||||
for(size_t i = 0; i < unico.size(); i++)
|
for(size_t i = 0; i < unico.size(); i++)
|
||||||
{
|
{
|
||||||
uint16_t cu = unico[i];
|
uint16_t cu = unico[i];
|
||||||
assert(ptNode);
|
assert(ptNode);
|
||||||
if(!isIn(ptNode->hmap, cu))
|
citer = ptNode->hmap.find(cu);
|
||||||
|
if(ptNode->hmap.end() == citer)
|
||||||
{
|
{
|
||||||
TrieNode * next = new TrieNode;
|
TrieNode * next = new TrieNode;
|
||||||
assert(next);
|
|
||||||
ptNode->hmap[cu] = next;
|
ptNode->hmap[cu] = next;
|
||||||
ptNode = next;
|
ptNode = next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptNode = ptNode->hmap[cu];
|
ptNode = citer->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ptNode->isLeaf = true;
|
ptNode->isLeaf = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user