Nuke binary plugins 15.0.5
 
Loading...
Searching...
No Matches
DD::Image::Hash Class Reference

#include <Hash.h>

Public Types

typedef U64 HashType
 

Public Member Functions

 Hash (const Hash &h)
 
 Hash (U64 v)
 
const Hashoperator= (const Hash &h)
 
void reset ()
 
void reset (U64 v)
 
bool operator== (const Hash &h) const
 
bool operator!= (const Hash &h) const
 
bool operator< (const Hash &h) const
 
U64 value () const
 
U64 getHash () const
 
bool isDefault () const
 
void append (const void *data, size_t length)
 
void append (const char *)
 
void append (const std::string &s)
 
void append (bool)
 
void append (int)
 
void append (unsigned)
 
void append (float)
 
void append (double)
 
void append (const Hash &)
 
void append (const std::set< int > &intset)
 
void append (const std::map< int, int > &iimap)
 
void append (U64)
 
template<class T >
void append (const std::vector< T > &vec)
 
template<class T >
Hashoperator<< (const T &v)
 
void newvalue ()
 

Detailed Description

Generates and maintaines a hash sum of data. If the hashes of two pieces of data are equal it is extremely likely the two pieces of data are equal.

To generate a hash, make one of these objects, then reset() it, then call append() with each piece of data you want to include. You can then compare it with other hashes, or extract the numerical value with value().

The algorithim used is a 64-bit CRC checksum, using the CRC-64-ECMA-182 polynominal (lsb representation 0x42F0E1EBA9EA3693). Some people worry that this is not a cryptographcally sound checksum, but that is not needed when the data is not being produced by something that is actively trying to subvert the checksum. For random data it is equally strong.

Member Function Documentation

◆ reset()

void DD::Image::Hash::reset ( )
inline

◆ append() [1/11]

void Hash::append ( const void *  data,
size_t  length 
)

Add the n bytes starting at pointer to the hash.

Warning: this call is for appending blocks of data together. A zero-length block will not change the hash, and the hash is the same no matter how the same block is split into calls to this. This will cause the hash to fail if you actually care about this, for instance if you have several variable-sized arrays of data. Swapping a zero-length and non-zero-length one, or moving data from the end of one to the start of the next, will not change the hash. The solution is to append the length as well.

◆ append() [2/11]

void Hash::append ( const char *  ptr)

Add a null-terminated string or a null pointer to the hash.

The zero-length string and the null pointer hash to different values, and those are different than not calling this.

◆ append() [3/11]

void Hash::append ( bool  v)

Add a bool value to the hash. This is different than any other possible append (as it only adds 1 bit to the hash rather than a multiple of 8) and thus it is also useful for marking where zero-length arrays are.

◆ append() [4/11]

void Hash::append ( int  value)

Add an integer value to the hash. Same as using append(&value, sizeof(int)) on a LSB-first machine. This is intended for hashing enumeration values.

◆ append() [5/11]

void Hash::append ( unsigned  value)

Add an unsigned value to the hash. Same as using append(&value, sizeof(unsigned)) on a LSB-first machine. This is intended for hashing enumeration or size values.

◆ append() [6/11]

void Hash::append ( float  value)

Add a float value to the hash. Same as using append(&value, sizeof(float)) (this may change on MSB machines).

◆ append() [7/11]

void Hash::append ( double  value)

Add a double value to the hash. Same as using append(&value, sizeof(float)) (this may change on MSB machines).

◆ append() [8/11]

void Hash::append ( const Hash h)

Add another hash to this hash.

◆ append() [9/11]

void Hash::append ( const std::set< int > &  intset)

Add an intset to the hash.

◆ append() [10/11]

void Hash::append ( const std::map< int, int > &  iimap)

Add a std::map<int, int> to the hash.

◆ append() [11/11]

void Hash::append ( U64  value)

Add a 64 bit value to this hash.



©2024 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com