mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
rewriting trie.cpp/h
This commit is contained in:
parent
8d1c326a40
commit
ea36cf6794
20
src/Trie.cpp
20
src/Trie.cpp
@ -60,7 +60,7 @@ namespace CppJieba
|
|||||||
|
|
||||||
bool Trie::init()
|
bool Trie::init()
|
||||||
{
|
{
|
||||||
if(_getInitFlag())
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogError("already initted!");
|
LogError("already initted!");
|
||||||
return false;
|
return false;
|
||||||
@ -157,7 +157,7 @@ namespace CppJieba
|
|||||||
|
|
||||||
bool Trie::destroy()
|
bool Trie::destroy()
|
||||||
{
|
{
|
||||||
if(NULL == _root)
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -180,19 +180,19 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TrieNodeInfo* Trie::findPrefix(const string& utf8Str)
|
const TrieNodeInfo* Trie::findPrefix(const string& str)
|
||||||
{
|
{
|
||||||
if(NULL == _root)
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogFatal("trie not initted!");
|
LogFatal("trie not initted!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(utf8Str.empty())
|
if(str.empty())
|
||||||
{
|
{
|
||||||
LogError("utf8Str is empty");
|
LogError("str is empty");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
string uniStr = utf8ToUnicode(utf8Str);
|
string uniStr = decode(str);
|
||||||
if(uniStr.empty())
|
if(uniStr.empty())
|
||||||
{
|
{
|
||||||
LogError("utf8ToUnicode return empty star");
|
LogError("utf8ToUnicode return empty star");
|
||||||
@ -243,7 +243,7 @@ namespace CppJieba
|
|||||||
|
|
||||||
const TrieNodeInfo* Trie::_findUniStr(const string& uniStr)
|
const TrieNodeInfo* Trie::_findUniStr(const string& uniStr)
|
||||||
{
|
{
|
||||||
if(NULL == _root)
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogFatal("trie not initted!");
|
LogFatal("trie not initted!");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -346,9 +346,9 @@ namespace CppJieba
|
|||||||
|
|
||||||
bool Trie::insert(const TrieNodeInfo& nodeInfo)
|
bool Trie::insert(const TrieNodeInfo& nodeInfo)
|
||||||
{
|
{
|
||||||
if(NULL == _root)
|
if(!_getInitFlag())
|
||||||
{
|
{
|
||||||
LogError("_root is NULL");
|
LogFatal("not initted!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ namespace CppJieba
|
|||||||
//const TrieNodeInfo* find(const string& uniStr);
|
//const TrieNodeInfo* find(const string& uniStr);
|
||||||
//const TrieNodeInfo* find(const ChUnicode* const chUniStr, size_t len);
|
//const TrieNodeInfo* find(const ChUnicode* const chUniStr, size_t len);
|
||||||
const TrieNodeInfo* find(const string& str);
|
const TrieNodeInfo* find(const string& str);
|
||||||
const TrieNodeInfo* findPrefix(const string& utf8Str);
|
const TrieNodeInfo* findPrefix(const string& str);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//double getWeight(const ChUnicode* uniStr, size_t len);
|
//double getWeight(const ChUnicode* uniStr, size_t len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user