update md5.hpp in limonp | change map type in TrieManager.hpp

This commit is contained in:
aholic 2013-12-16 07:01:50 +08:00
parent 0bc5f6f00b
commit a0f588a8af
2 changed files with 25 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -11,7 +11,7 @@ namespace CppJieba
class TrieManager
{
private:
unordered_map<const char*, Trie*> _tries;
unordered_map<std::string, Trie*> _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()];
}
}