From bfbd63f3e8e460065c44e78bc64967ce7f9ec8ce Mon Sep 17 00:00:00 2001 From: wyy Date: Tue, 8 Apr 2014 19:51:49 +0800 Subject: [PATCH] remove trie.find(xx,xx, vector) --- src/FullSegment.hpp | 7 ++++--- src/Trie.hpp | 20 -------------------- test/unittest/TTrie.cpp | 2 -- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/FullSegment.hpp b/src/FullSegment.hpp index 902c652..2f6d403 100644 --- a/src/FullSegment.hpp +++ b/src/FullSegment.hpp @@ -48,7 +48,7 @@ namespace CppJieba } //resut of searching in trie tree - vector > tRes; + DagType tRes; //max index of res's words int maxIdx = 0; @@ -61,9 +61,10 @@ namespace CppJieba for (Unicode::const_iterator uItr = begin; uItr != end; uItr++) { //find word start from uItr - if (_trie.find(uItr, end, tRes)) + if (_trie.find(uItr, end, 0, tRes)) { - for (vector >::const_iterator itr = tRes.begin(); itr != tRes.end(); itr++) + for(DagType::const_iterator itr = tRes.begin(); itr != tRes.end(); itr++) + //for (vector >::const_iterator itr = tRes.begin(); itr != tRes.end(); itr++) { wordLen = itr->second->word.size(); if (wordLen >= 2 || (tRes.size() == 1 && maxIdx <= uIdx)) diff --git a/src/Trie.hpp b/src/Trie.hpp index d0759cb..36400cf 100644 --- a/src/Trie.hpp +++ b/src/Trie.hpp @@ -118,26 +118,6 @@ namespace CppJieba return NULL; } - bool find(Unicode::const_iterator begin, Unicode::const_iterator end, vector >& res) const - { - TrieNodeMap::const_iterator citer; - TrieNode* p = _root; - for (Unicode::const_iterator itr = begin; itr != end; itr++) - { - citer = p->hmap.find(*itr); - if(p->hmap.end() == citer) - { - break; - } - p = citer->second; - if(p->isLeaf) - { - res.push_back(make_pair(itr-begin, p->ptTrieNodeInfo)); - } - } - return !res.empty(); - } - bool find(Unicode::const_iterator begin, Unicode::const_iterator end, size_t offset, DagType & res) const { TrieNode* p = _root; diff --git a/test/unittest/TTrie.cpp b/test/unittest/TTrie.cpp index 67dcf7a..166f46e 100644 --- a/test/unittest/TTrie.cpp +++ b/test/unittest/TTrie.cpp @@ -40,8 +40,6 @@ TEST(TrieTest, Test1) vector > vec; ASSERT_TRUE(TransCode::decode(word, uni)); //print(uni); - ASSERT_TRUE(trie.find(uni.begin(), uni.end(), vec)); - ASSERT_EQ(vec, res); ASSERT_TRUE(trie.find(uni.begin(), uni.end(), 0, map)); ASSERT_EQ(map, resMap); // print(vec);