use map as DagType to fix a unordered bug in different environment , by the way, it improves 1/6 speed

This commit is contained in:
wyy 2014-03-11 10:28:10 +08:00
parent 485383c669
commit 90d2280002
2 changed files with 4 additions and 4 deletions

View File

@ -62,7 +62,7 @@ namespace CppJieba
return os << nodeInfo.word << ":" << nodeInfo.freq << ":" << nodeInfo.tag << ":" << nodeInfo.logFreq ; return os << nodeInfo.word << ":" << nodeInfo.freq << ":" << nodeInfo.tag << ":" << nodeInfo.logFreq ;
} }
typedef unordered_map<uint, const TrieNodeInfo*> DagType; typedef map<uint, const TrieNodeInfo*> DagType;
class Trie class Trie
{ {
@ -227,7 +227,7 @@ namespace CppJieba
return !res.empty(); return !res.empty();
} }
bool find(Unicode::const_iterator begin, Unicode::const_iterator end, uint offset, unordered_map<uint, const TrieNodeInfo* > & res) const bool find(Unicode::const_iterator begin, Unicode::const_iterator end, uint offset, DagType & res) const
{ {
if(!_getInitFlag()) if(!_getInitFlag())
{ {

View File

@ -22,8 +22,8 @@ TEST(TrieTest, Test1)
EXPECT_EQ(nodeInfo, *trie.find(uni.begin(), uni.end())); EXPECT_EQ(nodeInfo, *trie.find(uni.begin(), uni.end()));
word = "清华大学"; word = "清华大学";
vector<pair<uint, const TrieNodeInfo*> > res; vector<pair<uint, const TrieNodeInfo*> > res;
unordered_map<uint, const TrieNodeInfo* > resMap; map<uint, const TrieNodeInfo* > resMap;
unordered_map<uint, const TrieNodeInfo* > map; map<uint, const TrieNodeInfo* > map;
const char * words[] = {"", "清华", "清华大学"}; const char * words[] = {"", "清华", "清华大学"};
for(uint i = 0; i < sizeof(words)/sizeof(words[0]); i++) for(uint i = 0; i < sizeof(words)/sizeof(words[0]); i++)
{ {