split out CRC32 code
This commit is contained in:
@@ -493,9 +493,13 @@ CString GetCwd()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reference: http://www.theorem.com/java/CRC32.java, rewritten by Glenn Maynard.
|
/*
|
||||||
* Public domain. */
|
* Calculate a standard CRC32. iCRC should be initialized to 0.
|
||||||
unsigned int GetHashForString ( const CString &s )
|
* References:
|
||||||
|
* http://www.theorem.com/java/CRC32.java,
|
||||||
|
* http://www.faqs.org/rfcs/rfc1952.html
|
||||||
|
*/
|
||||||
|
void CRC32( unsigned int &iCRC, const char *pBuffer, size_t iSize )
|
||||||
{
|
{
|
||||||
static unsigned tab[256];
|
static unsigned tab[256];
|
||||||
static bool initted = false;
|
static bool initted = false;
|
||||||
@@ -509,18 +513,27 @@ unsigned int GetHashForString ( const CString &s )
|
|||||||
tab[i] = i;
|
tab[i] = i;
|
||||||
for( int j = 0; j < 8; ++j )
|
for( int j = 0; j < 8; ++j )
|
||||||
{
|
{
|
||||||
if(tab[i] & 1) tab[i] = (tab[i] >> 1) ^ POLY;
|
if( tab[i] & 1 )
|
||||||
else tab[i] >>= 1;
|
tab[i] = (tab[i] >> 1) ^ POLY;
|
||||||
|
else
|
||||||
|
tab[i] >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned crc = 0;
|
unsigned crc = 0;
|
||||||
for(unsigned i = 0; i < s.size(); ++i)
|
for( unsigned i = 0; i < iSize; ++i )
|
||||||
crc = (crc >> 8) ^ tab[(crc ^ s[i]) & 0xFF];
|
iCRC = (iCRC >> 8) ^ tab[(iCRC ^ pBuffer[i]) & 0xFF];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int GetHashForString ( const CString &s )
|
||||||
|
{
|
||||||
|
unsigned crc = 0;
|
||||||
|
CRC32( crc, s.data(), s.size() );
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return true if "dir" is empty or does not exist. */
|
/* Return true if "dir" is empty or does not exist. */
|
||||||
bool DirectoryIsEmpty( const CString &dir )
|
bool DirectoryIsEmpty( const CString &dir )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ CString join( const CString &Delimitor, CStringArray::const_iterator begin, CStr
|
|||||||
|
|
||||||
CString GetCwd();
|
CString GetCwd();
|
||||||
|
|
||||||
|
void CRC32( unsigned int &iCRC, const char *pBuffer, size_t iSize );
|
||||||
unsigned int GetHashForString( const CString &s );
|
unsigned int GetHashForString( const CString &s );
|
||||||
unsigned int GetHashForFile( const CString &sPath );
|
unsigned int GetHashForFile( const CString &sPath );
|
||||||
unsigned int GetHashForDirectory( const CString &sDir ); // a hash value that remains the same as long as nothing in the directory has changed
|
unsigned int GetHashForDirectory( const CString &sDir ); // a hash value that remains the same as long as nothing in the directory has changed
|
||||||
|
|||||||
Reference in New Issue
Block a user