ImFusion SDK 4.3
Non-cryptographic Hashing

Tools and functions to compute non-cryptographics hashes, for instance to use them in std::unordered_map. More...

+ Collaboration diagram for Non-cryptographic Hashing:

Detailed Description

Tools and functions to compute non-cryptographics hashes, for instance to use them in std::unordered_map.

Classes

struct  EigenHasher< T >
 STL-compatible hasher for dense Eigen types (matrices, vectors, arrays). More...
 
struct  GenericHasher< T, PointerToMember >
 STL-compatible hasher for custom classes where you list the members to be hashed as template parameters. More...
 

Functions

uint64_t murmur64 (const ByteBufferView &buffer) noexcept
 Computes the non-cryptographic 64-bit MurmurHash2 on the input data.
 
uint64_t djb2 (const ByteBufferView &data) noexcept
 Computes the djb2 hash value of the input data.
 
template<typename T>
uint64_t combineHash (uint64_t seed, const T &object) noexcept
 Computes the hash of object using std::hash<T> and combines it with an already existing 64bit hash.
 
template<>
uint64_t combineHash (uint64_t seed, const uint64_t &hashToAdd) noexcept
 Combines existing 64bit hashes.
 
template<typename... Ts>
uint64_t genericHash (const Ts &... objects) noexcept
 Convenience function to compute the combined hash of an arbitrary number of inputs.
 

Function Documentation

◆ murmur64()

uint64_t murmur64 ( const ByteBufferView & buffer)
noexcept

#include <ImFusion/Core/Hashing.h>

Computes the non-cryptographic 64-bit MurmurHash2 on the input data.

MurmurHash2 exhibits excellent performance in terms of both computation speed and collision robustness and can therefore serve as default choice for all non-cryptographic applications.

See also
https://github.com/aappleby/smhasher/wiki

◆ djb2()

uint64_t djb2 ( const ByteBufferView & data)
noexcept

#include <ImFusion/Core/Hashing.h>

Computes the djb2 hash value of the input data.

Warning
This simplistic hashing algorithm is both slower and more prone to collisions than murmur64() and should not be used for new code.
See also
http://www.cse.yorku.ca/~oz/hash.html

◆ combineHash() [1/2]

template<typename T>
uint64_t combineHash ( uint64_t seed,
const T & object )
inlinenoexcept

#include <ImFusion/Core/Hashing.h>

Computes the hash of object using std::hash<T> and combines it with an already existing 64bit hash.

Example usage:

uint64_t hash = combineHash(0, object1);
hash = combineHash(hash, object2);
hash = combineHash(hash, object3);
uint64_t combineHash(uint64_t seed, const T &object) noexcept
Computes the hash of object using std::hash<T> and combines it with an already existing 64bit hash.
Definition Hashing.h:98

◆ combineHash() [2/2]

template<>
uint64_t combineHash ( uint64_t seed,
const uint64_t & hashToAdd )
inlinenoexcept

#include <ImFusion/Core/Hashing.h>

Combines existing 64bit hashes.

Example usage:

uint64_t hash = combineHash(0, std::hash<...>()(...));
hash = combineHash(hash, std::hash<...>()(...));
hash = combineHash(hash, std::hash<...>()(...));

◆ genericHash()

template<typename... Ts>
uint64_t genericHash ( const Ts &... objects)
inlinenoexcept

#include <ImFusion/Core/Hashing.h>

Convenience function to compute the combined hash of an arbitrary number of inputs.

Computes the individual hash of each argument using std::hash and combines them through combineHash(). Example usage:

int i = ...;
double d = ...;
std::string s = ...;
uint64_t hash = genericHash(i, d, s);
uint64_t genericHash(const Ts &... objects) noexcept
Convenience function to compute the combined hash of an arbitrary number of inputs.
Definition Hashing.h:133
See also
GenericHasher
Search Tab / S to search, Esc to close