From 313e05da1b337c3751d9a62d24f0c941af5ae88f Mon Sep 17 00:00:00 2001 From: wyy Date: Sat, 7 Dec 2013 20:25:28 -0800 Subject: [PATCH] ci for lunch --- src/MPSegment.hpp | 23 +++++++++---------- src/Trie.hpp | 56 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/MPSegment.hpp b/src/MPSegment.hpp index 288353f..cc60dc0 100644 --- a/src/MPSegment.hpp +++ b/src/MPSegment.hpp @@ -158,21 +158,22 @@ namespace CppJieba return false; } - vector > vp; + //vector > vp; for(Unicode::const_iterator it = begin; it != end; it++) { segContext.push_back(SegmentChar(*it)); SegmentChar& back = segContext.back(); - int i = it - begin; - vp.clear(); - if(_trie.find(it, end, vp)) - { - for(uint j = 0; j < vp.size(); j++) - { - uint nextp = vp[j].first + i; - back.dag[nextp] = vp[j].second; - } - } + uint i = it - begin; + _trie.find(it, end, i, back.dag); + //vp.clear(); + //if(_trie.find(it, end, vp)) + //{ + // for(uint j = 0; j < vp.size(); j++) + // { + // uint nextp = vp[j].first + i; + // back.dag[nextp] = vp[j].second; + // } + //} if(back.dag.end() == back.dag.find(i)) { back.dag[i] = NULL; diff --git a/src/Trie.hpp b/src/Trie.hpp index c39277a..e7956f7 100644 --- a/src/Trie.hpp +++ b/src/Trie.hpp @@ -157,15 +157,15 @@ namespace CppJieba bool _getInitFlag()const{return _initFlag;}; public: - const TrieNodeInfo* find(const string& str)const - { - Unicode uintVec; - if(!TransCode::decode(str, uintVec)) - { - return NULL; - } - return find(uintVec.begin(), uintVec.end()); - } + //const TrieNodeInfo* find(const string& str)const + //{ + // Unicode uintVec; + // if(!TransCode::decode(str, uintVec)) + // { + // return NULL; + // } + // return find(uintVec.begin(), uintVec.end()); + //} const TrieNodeInfo* find(Unicode::const_iterator begin, Unicode::const_iterator end)const { @@ -244,6 +244,44 @@ namespace CppJieba return !res.empty(); } + bool find(Unicode::const_iterator begin, Unicode::const_iterator end, uint offset, unordered_map & res) const + { + if(!_getInitFlag()) + { + LogFatal("trie not initted!"); + return false; + } + if (begin >= end) + { + LogFatal("begin >= end"); + return false; + } + TrieNode* p = _root; + for (Unicode::const_iterator itr = begin; itr != end; itr++) + { + if(p->hmap.find(*itr) == p-> hmap.end()) + { + break; + } + p = p->hmap[*itr]; + if(p->isLeaf) + { + uint pos = p->nodeInfoVecPos; + if(pos < _nodeInfoVec.size()) + { + //res.push_back(make_pair(itr-begin, &_nodeInfoVec[pos])); + res[itr-begin + offset] = &_nodeInfoVec[pos]; + } + else + { + LogFatal("node's nodeInfoVecPos is out of _nodeInfoVec's range"); + return false; + } + } + } + return !res.empty(); + } + //bool find(const Unicode& unico, vector >& res)const //{ // if (!unico.empty())