mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update md5.hpp in limonp | change map type in TrieManager.hpp
This commit is contained in:
parent
0bc5f6f00b
commit
a0f588a8af
@ -336,7 +336,7 @@ public:
|
|||||||
|
|
||||||
/// Load a file from disk and digest it
|
/// Load a file from disk and digest it
|
||||||
// Digests a file and returns the result.
|
// Digests a file and returns the result.
|
||||||
char* digestFile( const char *filename )
|
const char* digestFile( const char *filename )
|
||||||
{
|
{
|
||||||
Init() ;
|
Init() ;
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ public:
|
|||||||
|
|
||||||
if(NULL == filename || (file = fopen (filename, "rb")) == NULL )
|
if(NULL == filename || (file = fopen (filename, "rb")) == NULL )
|
||||||
{
|
{
|
||||||
return "";
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -362,10 +362,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Digests a byte-array already in memory
|
/// Digests a byte-array already in memory
|
||||||
char* digestMemory( BYTE *memchunk, int len )
|
const char* digestMemory( BYTE *memchunk, int len )
|
||||||
{
|
{
|
||||||
if (NULL == memchunk)
|
if (NULL == memchunk)
|
||||||
return "";
|
return NULL;
|
||||||
|
|
||||||
Init() ;
|
Init() ;
|
||||||
Update( memchunk, len ) ;
|
Update( memchunk, len ) ;
|
||||||
@ -375,10 +375,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Digests a string and prints the result.
|
// Digests a string and prints the result.
|
||||||
char* digestString(const char *string )
|
const char* digestString(const char *string )
|
||||||
{
|
{
|
||||||
if (string == NULL)
|
if (string == NULL)
|
||||||
return "";
|
return NULL;
|
||||||
|
|
||||||
Init() ;
|
Init() ;
|
||||||
Update( (unsigned char*)string, strlen(string) ) ;
|
Update( (unsigned char*)string, strlen(string) ) ;
|
||||||
@ -397,10 +397,14 @@ inline bool md5String(const char* str, std::string& res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
res = md5.digestString(str);
|
const char *pRes = md5.digestString(str);
|
||||||
|
if (NULL == pRes)
|
||||||
if (res == "")
|
{
|
||||||
|
res = "";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pRes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,10 +417,15 @@ inline bool md5File(const char* filepath, std::string& res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
res = md5.digestFile(filepath);
|
const char *pRes = md5.digestFile(filepath);
|
||||||
|
|
||||||
if (res == "")
|
if (NULL == pRes)
|
||||||
|
{
|
||||||
|
res = "";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pRes;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace CppJieba
|
|||||||
class TrieManager
|
class TrieManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
unordered_map<const char*, Trie*> _tries;
|
unordered_map<std::string, Trie*> _tries;
|
||||||
TrieManager(){};
|
TrieManager(){};
|
||||||
TrieManager(TrieManager& tm){};
|
TrieManager(TrieManager& tm){};
|
||||||
public:
|
public:
|
||||||
@ -25,8 +25,10 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
else
|
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;
|
Trie* trie = NULL;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -59,6 +61,7 @@ namespace CppJieba
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
LogInfo("find a exits trie for md5: '%s'", md5.c_str());
|
||||||
return _tries[md5.c_str()];
|
return _tries[md5.c_str()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user