mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
修复typename在不同版本编译器的兼容问题
This commit is contained in:
parent
0edb2b13cc
commit
e0e0a6b976
41
src/Trie.hpp
41
src/Trie.hpp
@ -58,7 +58,7 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
typename NextMap::const_iterator iter = next->find(key);
|
NextMap::const_iterator iter = next->find(key);
|
||||||
if(iter == next->end())
|
if(iter == next->end())
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -86,11 +86,11 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
const DictUnit* find(typename Unicode::const_iterator begin, typename Unicode::const_iterator end) const
|
const DictUnit* find(Unicode::const_iterator begin, Unicode::const_iterator end) const
|
||||||
{
|
{
|
||||||
typename TrieNode::NextMap::const_iterator citer;
|
TrieNode::NextMap::const_iterator citer;
|
||||||
const TrieNode* ptNode = _root;
|
const TrieNode* ptNode = _root;
|
||||||
for(typename Unicode::const_iterator it = begin; it != end; it++)
|
for(Unicode::const_iterator it = begin; it != end; it++)
|
||||||
{// build automation
|
{// build automation
|
||||||
assert(ptNode);
|
assert(ptNode);
|
||||||
if(NULL == ptNode->next || ptNode->next->end() == (citer = ptNode->next->find(*it)))
|
if(NULL == ptNode->next || ptNode->next->end() == (citer = ptNode->next->find(*it)))
|
||||||
@ -103,14 +103,13 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
// aho-corasick-automation
|
// aho-corasick-automation
|
||||||
void find(
|
void find(
|
||||||
typename Unicode::const_iterator begin,
|
Unicode::const_iterator begin,
|
||||||
typename Unicode::const_iterator end,
|
Unicode::const_iterator end,
|
||||||
vector<struct SegmentChar>& res
|
vector<struct SegmentChar>& res
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
res.resize(end - begin);
|
res.resize(end - begin);
|
||||||
const TrieNode * now = _root;
|
const TrieNode * now = _root;
|
||||||
//typename TrieNode::NextMap::const_iterator iter;
|
|
||||||
const TrieNode* node;
|
const TrieNode* node;
|
||||||
// compiler will complain warnings if only "i < end - begin" .
|
// compiler will complain warnings if only "i < end - begin" .
|
||||||
for (size_t i = 0; i < size_t(end - begin); i++)
|
for (size_t i = 0; i < size_t(end - begin); i++)
|
||||||
@ -118,7 +117,7 @@ namespace CppJieba
|
|||||||
Unicode::value_type ch = *(begin + i);
|
Unicode::value_type ch = *(begin + i);
|
||||||
res[i].uniCh = ch;
|
res[i].uniCh = ch;
|
||||||
assert(res[i].dag.empty());
|
assert(res[i].dag.empty());
|
||||||
res[i].dag.push_back(pair<typename vector<Unicode >::size_type, const DictUnit* >(i, NULL));
|
res[i].dag.push_back(pair<vector<Unicode >::size_type, const DictUnit* >(i, NULL));
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
|
|
||||||
// rollback
|
// rollback
|
||||||
@ -153,7 +152,7 @@ namespace CppJieba
|
|||||||
if (temp->ptValue)
|
if (temp->ptValue)
|
||||||
{
|
{
|
||||||
size_t pos = i - temp->ptValue->word.size() + 1;
|
size_t pos = i - temp->ptValue->word.size() + 1;
|
||||||
res[pos].dag.push_back(pair<typename vector<Unicode >::size_type, const DictUnit* >(i, temp->ptValue));
|
res[pos].dag.push_back(pair<vector<Unicode >::size_type, const DictUnit* >(i, temp->ptValue));
|
||||||
if(pos == i)
|
if(pos == i)
|
||||||
{
|
{
|
||||||
res[pos].dag[0].second = temp->ptValue;
|
res[pos].dag[0].second = temp->ptValue;
|
||||||
@ -166,14 +165,14 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool find(
|
bool find(
|
||||||
typename Unicode::const_iterator begin,
|
Unicode::const_iterator begin,
|
||||||
typename Unicode::const_iterator end,
|
Unicode::const_iterator end,
|
||||||
DagType & res,
|
DagType & res,
|
||||||
size_t offset = 0) const
|
size_t offset = 0) const
|
||||||
{
|
{
|
||||||
const TrieNode * ptNode = _root;
|
const TrieNode * ptNode = _root;
|
||||||
typename TrieNode::NextMap::const_iterator citer;
|
TrieNode::NextMap::const_iterator citer;
|
||||||
for(typename Unicode::const_iterator itr = begin; itr != end ; itr++)
|
for(Unicode::const_iterator itr = begin; itr != end ; itr++)
|
||||||
{
|
{
|
||||||
assert(ptNode);
|
assert(ptNode);
|
||||||
if(NULL == ptNode->next || ptNode->next->end() == (citer = ptNode->next->find(*itr)))
|
if(NULL == ptNode->next || ptNode->next->end() == (citer = ptNode->next->find(*itr)))
|
||||||
@ -189,7 +188,7 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res.push_back(pair<typename vector<Unicode >::size_type, const DictUnit* >(itr - begin + offset, ptNode->ptValue));
|
res.push_back(pair<vector<Unicode >::size_type, const DictUnit* >(itr - begin + offset, ptNode->ptValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,19 +201,19 @@ namespace CppJieba
|
|||||||
assert(_root->ptValue == NULL);
|
assert(_root->ptValue == NULL);
|
||||||
assert(_root->next);
|
assert(_root->next);
|
||||||
_root->fail = NULL;
|
_root->fail = NULL;
|
||||||
for(typename TrieNode::NextMap::iterator iter = _root->next->begin(); iter != _root->next->end(); iter++) {
|
for(TrieNode::NextMap::iterator iter = _root->next->begin(); iter != _root->next->end(); iter++) {
|
||||||
iter->second->fail = _root;
|
iter->second->fail = _root;
|
||||||
que.push(iter->second);
|
que.push(iter->second);
|
||||||
}
|
}
|
||||||
TrieNode* back = NULL;
|
TrieNode* back = NULL;
|
||||||
typename TrieNode::NextMap::iterator backiter;
|
TrieNode::NextMap::iterator backiter;
|
||||||
while(!que.empty()) {
|
while(!que.empty()) {
|
||||||
TrieNode * now = que.front();
|
TrieNode * now = que.front();
|
||||||
que.pop();
|
que.pop();
|
||||||
if(now->next == NULL) {
|
if(now->next == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for(typename TrieNode::NextMap::iterator iter = now->next->begin(); iter != now->next->end(); iter++) {
|
for(TrieNode::NextMap::iterator iter = now->next->begin(); iter != now->next->end(); iter++) {
|
||||||
back = now->fail;
|
back = now->fail;
|
||||||
while(back != NULL) {
|
while(back != NULL) {
|
||||||
if(back->next && (backiter = back->next->find(iter->first)) != back->next->end())
|
if(back->next && (backiter = back->next->find(iter->first)) != back->next->end())
|
||||||
@ -250,13 +249,13 @@ namespace CppJieba
|
|||||||
{
|
{
|
||||||
TrieNode* ptNode = _root;
|
TrieNode* ptNode = _root;
|
||||||
|
|
||||||
typename TrieNode::NextMap::const_iterator kmIter;
|
TrieNode::NextMap::const_iterator kmIter;
|
||||||
|
|
||||||
for(typename Unicode::const_iterator citer = key.begin(); citer != key.end(); citer++)
|
for(Unicode::const_iterator citer = key.begin(); citer != key.end(); citer++)
|
||||||
{
|
{
|
||||||
if(NULL == ptNode->next)
|
if(NULL == ptNode->next)
|
||||||
{
|
{
|
||||||
ptNode->next = new typename TrieNode::NextMap;
|
ptNode->next = new TrieNode::NextMap;
|
||||||
}
|
}
|
||||||
kmIter = ptNode->next->find(*citer);
|
kmIter = ptNode->next->find(*citer);
|
||||||
if(ptNode->next->end() == kmIter)
|
if(ptNode->next->end() == kmIter)
|
||||||
@ -283,7 +282,7 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
if(node->next)
|
if(node->next)
|
||||||
{
|
{
|
||||||
typename TrieNode::NextMap::iterator it;
|
TrieNode::NextMap::iterator it;
|
||||||
for(it = node->next->begin(); it != node->next->end(); it++)
|
for(it = node->next->begin(); it != node->next->end(); it++)
|
||||||
{
|
{
|
||||||
_deleteNode(it->second);
|
_deleteNode(it->second);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user