Public Types | |
typedef U64 | HashType |
Public Member Functions | |
Hash (const Hash &h) | |
Hash (U64 v) | |
const Hash & | operator= (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 |
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 > | |
Hash & | operator<< (const T &v) |
void | newvalue () |
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.
|
inline |
Reset the hash to it's initial value. This is not zero.
Referenced by DD::Image::ReadGeo::_validate(), DD::Image::GeometryList::add_object(), DD::Image::GeoOp::get_geometry(), DD::Image::GeoOp::get_geometry_hash(), and DD::Image::LUT::validate().
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.
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.
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.
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.
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.
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).
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).
void Hash::append | ( | const Hash & | h | ) |
Add another hash to this hash.
void Hash::append | ( | const std::set< int > & | intset | ) |
Add an intset to the hash.
void Hash::append | ( | const std::map< int, int > & | iimap | ) |
Add a std::map<int, int> to the hash.
void Hash::append | ( | U64 | value | ) |
Add a 64 bit value to this hash.
©2019 The Foundry Visionmongers, Ltd. All Rights Reserved. |