Public Member Functions | |
| Hash () | |
| Initalise all with default, no data hashed. | |
| Hash (void *data, uint64__ length) | |
| void | GenerateHash (void *data, uint64__ length) |
| void | HashFileInfo (Dedupe::FileInfo &info) |
| void | HashMultiplyFileInfo (Dedupe::FileStream &stream) |
| void | AddToHash (void *data, uint64__ length) |
| T | GetHash () |
| bool | operator== (Hash< T > &h1) const |
| bool | operator!= (Hash< T > &h1) |
| void | Display () |
Static Public Member Functions | |
| static T | GetHash (void *data, uint64__ length, Hash &object) |
Definition at line 28 of file hash.h.
| Dedupe::Hash::Hash< T >::Hash | ( | void * | data, | |
| uint64__ | length | |||
| ) | [inline] |
Initialise the class and hashes the given data
| data | The data which to hash | |
| length | The length of the datafield |
Definition at line 47 of file hash.h.
:hash ( 0 ),
offset( (sizeof(T) > 4)?(14695981039346656037ULL):(2166136261UL) ),
magic( (sizeof(T) > 4)?(1099511628211ULL):(16777619UL) )
{
hash = offset;
uint64__ i = 0;
char *data2 = static_cast<char*>(data);
T *longdata = static_cast<T*>(data);
if((length % sizeof(T)) != 0) //If the length isn't dividable by the size of the hashvar, hash the single bytes until it is easy hashable
{
for(; i < (length % sizeof(T)); i++)
{
hash = (hash ^ *(data2++)) * magic; //hashen
}
}
longdata += (length % sizeof(T));
for(; i < length; i+=sizeof(T))
{
hash = (hash ^ *(longdata++)) * magic; //Hash the rest
}
}
| void Dedupe::Hash::Hash< T >::AddToHash | ( | void * | data, | |
| uint64__ | length | |||
| ) | [inline] |
Adds data to the hash WITH using the already hashed data
| data | The data to hash | |
| length | The length of data |
Definition at line 158 of file hash.h.
{
if(hash == 0)
{
return;
}
uint64__ i = 0;
char *data2 = static_cast<char*>(data);
T *longdata = static_cast<T*>(data);
if((length % sizeof(T)) != 0)
{
for(; i < (length % sizeof(T)); i++)
{
hash = (hash ^ *data2++) * magic;
}
}
longdata += (length % sizeof(T));
for(; i < length; i += sizeof(T))
{
hash = (hash ^ *longdata++) * magic;
}
}
| void Dedupe::Hash::Hash< T >::Display | ( | ) |
Displays the Hash in the console.
| void Dedupe::Hash::Hash< T >::GenerateHash | ( | void * | data, | |
| uint64__ | length | |||
| ) | [inline] |
Attention: Resets everything to start. DO NOT USE if you want to hash ADDITIONAL data Generates a new hash
| data | The data to hash | |
| length | The length of the datafield |
Definition at line 74 of file hash.h.
{
hash = offset;
uint64__ i = 0;
char *data2 = static_cast<char*>(data);
T *longdata = static_cast<T>(data);
if((length % sizeof(T)) != 0)
{
for(; i < (length % sizeof(T)); i++)
{
hash = (hash ^ *data2++) * magic;
}
}
longdata += (length % sizeof(T));
for(; i < length; i += sizeof(T))
{
hash = (hash ^ *longdata++) * magic;
}
}
| static T Dedupe::Hash::Hash< T >::GetHash | ( | void * | data, | |
| uint64__ | length, | |||
| Hash< T > & | object | |||
| ) | [inline, static] |
Static function to get a hash out of the given data
| data | The data to hash | |
| length | The length of the data |
Definition at line 97 of file hash.h.
{
T nHash = object.offset;
uint64__ i = 0;
char *data2 = static_cast<char*>(data);
T *longdata = static_cast<T*>(data);
if((length % sizeof(T)) != 0)
{
for(; i < (length % sizeof(T)); i++)
{
nHash = (nHash ^ *data2++) * object.magic;
}
}
longdata += (length % sizeof(T));
for(; i < length; i += sizeof(T))
{
nHash = (nHash ^ *longdata++) * object.magic;
}
return nHash;
}
| T Dedupe::Hash::Hash< T >::GetHash | ( | ) | [inline] |
| void Dedupe::Hash::Hash< T >::HashFileInfo | ( | Dedupe::FileInfo & | info | ) | [inline] |
Generats the hash for a FileInfo.
| inf | A reference to the FileInfo |
Definition at line 120 of file hash.h.
References Dedupe::FileInfo::GetPath(), and Dedupe::FileInfo::SetHash().
Referenced by Dedupe::Core::Kernel::AutoUpdateDatabase(), and Dedupe::Core::Kernel::FindHashDuplicatesExtern().
{
boost::filesystem::ifstream *file = new boost::filesystem::ifstream();
char *data = new char[FILE_PACKET_SIZE];
unsigned long long int length = 0;
file->open(info.GetPath(), ifstream::in);
file->seekg(0, ios::end);
length = file->tellg();
file->seekg(0, ios::beg);
file->read(data, (FILE_PACKET_SIZE > length)?(length):(FILE_PACKET_SIZE));
Hash<T> hash(data, (FILE_PACKET_SIZE > length)?(length):(FILE_PACKET_SIZE));
length -= (104857600 > length)?(length):(FILE_PACKET_SIZE);
while(file->good() && length > 0)
{
file->read(data, (FILE_PACKET_SIZE > length)?(length):(FILE_PACKET_SIZE));
hash.AddToHash(data, (FILE_PACKET_SIZE > length)?(length):(FILE_PACKET_SIZE));
length -= FILE_PACKET_SIZE;
}
file->close();
info.SetHash( hash.GetHash() );
delete file;
delete data;
}
| void Dedupe::Hash::Hash< T >::HashMultiplyFileInfo | ( | Dedupe::FileStream & | stream | ) | [inline] |
1.7.1