Public Member Functions | Static Public Member Functions

Dedupe::Hash::Hash64 Class Reference

Inheritance diagram for Dedupe::Hash::Hash64:
Dedupe::Core::Kernel

Public Member Functions

 Hash64 ()
 Hash64 (void *data, uint64__ length)
void GenerateHash (void *data, uint64__ length)
void HashMultiplyFileInfo (Dedupe::FileStream &stream)
void AddToHash (void *data, uint64__ length)
uint64__ GetHash ()
void Display ()
bool operator== (const Hash64 &h1)
bool operator!= (const Hash64 &h1)

Static Public Member Functions

static uint64__ GetHash (void *data, uint64__ length)

Detailed Description

Definition at line 90 of file hash.h.


Constructor & Destructor Documentation

Hash64::Hash64 ( void   ) 

Initiate the class with a 0 hash

Definition at line 9 of file hash64.cpp.

{
        hash = 0;
}

Hash64::Hash64 ( void *  data,
uint64__  length 
)

Initiate the class and generate a hash out of the data

Parameters:
data The datafield providing the binary data to generate the hash.
length The length of the datafield.

Definition at line 14 of file hash64.cpp.

{
        hash = OFFSET_BASIS64;
        uint64__ i = 0;
        char *data2 = static_cast<char*>(data);
        uint64__ *longdata = static_cast<uint64__*>(data);
        if((length % sizeof(uint64__)) != 0)
        {
                for(; i < (length % sizeof(uint64__)); i++)
                {
                        hash = (hash ^ *data2++) * MAGIC64;
                }
        }
        longdata += (length % sizeof(uint64__));
        for(; i < length; i += sizeof(uint64__))
        {
                hash = (hash ^ *longdata++) * MAGIC64;
        }
}


Member Function Documentation

void Hash64::AddToHash ( void *  data,
uint64__  length 
)

The function add data to the Hash. Reqiers a initiated class and a genrated hash.

Parameters:
data The datafield providing the binary data to generate the hash.
length The length of the datafield.

Definition at line 54 of file hash64.cpp.

{
        if(hash == 0)
        {
                return;
        }
        uint64__ i = 0;
        char *data2 = static_cast<char*>(data);
        uint64__ *longdata = static_cast<uint64__*>(data);
        if((length % sizeof(uint64__)) != 0)
        {
                for(; i < (length % sizeof(uint64__)); i++)
                {
                        hash = (hash ^ *data2++) * MAGIC64;
                }
        }
        longdata += (length % sizeof(uint64__));
        for(; i < length; i += sizeof(uint64__))
        {
                hash = (hash ^ *longdata++) * MAGIC64;
        }
}

void Hash64::Display (  ) 

Displays the Hash in the console.

Definition at line 77 of file hash64.cpp.

{
        if(this->hash == 0)
        {
                cout << "Empty Hash" << endl;
                return;
        }
        cout << "Hash: " << hex << hash << endl;
}

void Hash64::GenerateHash ( void *  data,
uint64__  length 
)

Generates out of the data a new Hash. The function overrides the old hash.

Parameters:
data The datafield providing the binary data to generate the hash.
length The length of the datafield.

Definition at line 34 of file hash64.cpp.

{
        hash = OFFSET_BASIS64;
        uint64__ i = 0;
        char *data2 = static_cast<char*>(data);
        uint64__ *longdata = static_cast<uint64__*>(data);
        if((length % sizeof(uint64__)) != 0)
        {
                for(; i < (length % sizeof(uint64__)); i++)
                {
                        hash = (hash ^ *data2++) * MAGIC64;
                }
        }
        longdata += (length % sizeof(uint64__));
        for(; i < length; i += sizeof(uint64__))
        {
                hash = (hash ^ *longdata++) * MAGIC64;
        }
}

uint64__ Hash64::GetHash ( void *  data,
uint64__  length 
) [static]

Generates out of the data a new Hash and returns it

Parameters:
data The datafield providing the binary data to generate the hash.
length The length of the datafield.
Returns:
The Hash as a 64-Bit integer

Definition at line 87 of file hash64.cpp.

{
        uint64__ nHash = OFFSET_BASIS64;
        uint64__ i = 0;
        char *data2 = static_cast<char*>(data);
        uint64__ *longdata = static_cast<uint64__*>(data);
        if((length % sizeof(uint64__)) != 0)
        {
                for(; i < (length % sizeof(uint64__)); i++)
                {
                        nHash = (nHash ^ *data2++) * MAGIC64;
                }
        }
        longdata += (length % sizeof(uint64__));
        for(; i < length; i += sizeof(uint64__))
        {
                nHash = (nHash ^ *longdata++) * MAGIC64;
        }
        return nHash;
}

uint64__ Dedupe::Hash::Hash64::GetHash (  )  [inline]

Returns the hash as a 64 bit integer

Returns:
The hash as 64 bit unsigned integer.

Definition at line 129 of file hash.h.

                {
                        return hash;
                }

void Hash64::HashMultiplyFileInfo ( Dedupe::FileStream &  stream  ) 

Generats for all given FileInfo objects the hash

Parameters:
stream A pointer to the filestream with the FileInfo objects

Definition at line 108 of file hash64.cpp.

References Dedupe::Hash::Hash32::AddToHash(), and Dedupe::Hash::Hash32::GetHash().

{
        Dedupe::FileStream::iterator it;
        ifstream *file = new ifstream();
        char *data = new char[104857600];
        unsigned long long int length = 0;
        for(it = stream.begin(); it < stream.end(); it++)
        {
                file->open(it->GetPath().c_str(), ifstream::in);
                file->seekg(0, ios::end);
                length = file->tellg();
                file->seekg(0, ios::beg);

                file->read(data, (104857600 > length)?(length):(104857600));
                Hash32 hash(data, (104857600 > length)?(length):(104857600));
                length -= (104857600 > length)?(length):(104857600);
                while(file->good() && length > 0)
                {
                        file->read(data, (104857600 > length)?(length):(104857600));
                        hash.AddToHash(data, (104857600 > length)?(length):(104857600));
                        length -= 104857600;
                }
                file->close();
                it->SetHash( hash.GetHash() );
        }
        delete file;
        delete data;
}


The documentation for this class was generated from the following files: