From a0f588a8af189e0265f3c2da86ef1536e2175edd Mon Sep 17 00:00:00 2001 From: aholic Date: Mon, 16 Dec 2013 07:01:50 +0800 Subject: [PATCH] update md5.hpp in limonp | change map type in TrieManager.hpp --- src/Limonp/md5.hpp | 31 ++++++++++++++++++++----------- src/TrieManager.hpp | 7 +++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Limonp/md5.hpp b/src/Limonp/md5.hpp index 3673d57..b01be20 100644 --- a/src/Limonp/md5.hpp +++ b/src/Limonp/md5.hpp @@ -336,7 +336,7 @@ public: /// Load a file from disk and digest it // Digests a file and returns the result. - char* digestFile( const char *filename ) + const char* digestFile( const char *filename ) { Init() ; @@ -347,7 +347,7 @@ public: if(NULL == filename || (file = fopen (filename, "rb")) == NULL ) { - return ""; + return NULL; } else { @@ -362,10 +362,10 @@ public: } /// Digests a byte-array already in memory - char* digestMemory( BYTE *memchunk, int len ) + const char* digestMemory( BYTE *memchunk, int len ) { if (NULL == memchunk) - return ""; + return NULL; Init() ; Update( memchunk, len ) ; @@ -375,10 +375,10 @@ public: } // Digests a string and prints the result. - char* digestString(const char *string ) + const char* digestString(const char *string ) { if (string == NULL) - return ""; + return NULL; Init() ; Update( (unsigned char*)string, strlen(string) ) ; @@ -397,10 +397,14 @@ inline bool md5String(const char* str, std::string& res) } MD5 md5; - res = md5.digestString(str); - - if (res == "") + const char *pRes = md5.digestString(str); + if (NULL == pRes) + { + res = ""; return false; + } + + res = pRes; return true; } @@ -413,10 +417,15 @@ inline bool md5File(const char* filepath, std::string& res) } MD5 md5; - res = md5.digestFile(filepath); + const char *pRes = md5.digestFile(filepath); - if (res == "") + if (NULL == pRes) + { + res = ""; return false; + } + + res = pRes; return true; } } diff --git a/src/TrieManager.hpp b/src/TrieManager.hpp index 612fbc9..2590c89 100644 --- a/src/TrieManager.hpp +++ b/src/TrieManager.hpp @@ -11,7 +11,7 @@ namespace CppJieba class TrieManager { private: - unordered_map _tries; + unordered_map _tries; TrieManager(){}; TrieManager(TrieManager& tm){}; public: @@ -25,8 +25,10 @@ namespace CppJieba } else { - if (_tries.find(md5.c_str()) == _tries.end()) + LogInfo("md5 for file '%s': %s", dictpath, md5.c_str()); + if (_tries.find(md5) == _tries.end()) { + LogInfo("create a new trie for md5: '%s'", md5.c_str()); Trie* trie = NULL; try { @@ -59,6 +61,7 @@ namespace CppJieba } else { + LogInfo("find a exits trie for md5: '%s'", md5.c_str()); return _tries[md5.c_str()]; } }