Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
HashCombine.h File Reference

Go to the source code of this file.

Macros

#define JPH_MAKE_HASH_STRUCT(type, name, ...)
 
#define JPH_MAKE_HASHABLE(type, ...)
 

Functions

JPH_NAMESPACE_BEGIN uint64 HashBytes (const void *inData, uint inSize, uint64 inSeed=0xcbf29ce484222325UL)
 
uint64 Hash64 (uint64 inValue)
 
template<typename T >
void HashCombineHelper (size_t &ioSeed, const T &inValue)
 Helper function that hashes a single value into ioSeed Taken from: https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x. More...
 
template<typename... Values>
void HashCombine (std::size_t &ioSeed, Values... inValues)
 

Macro Definition Documentation

◆ JPH_MAKE_HASH_STRUCT

#define JPH_MAKE_HASH_STRUCT (   type,
  name,
  ... 
)
Value:
struct [[nodiscard]] name \
{ \
std::size_t operator()(const type &t) const \
{ \
std::size_t ret = 0; \
::JPH::HashCombine(ret, __VA_ARGS__); \
return ret; \
} \
};

◆ JPH_MAKE_HASHABLE

#define JPH_MAKE_HASHABLE (   type,
  ... 
)
Value:
JPH_SUPPRESS_WARNING_PUSH \
JPH_SUPPRESS_WARNINGS \
namespace std \
{ \
template<> \
JPH_MAKE_HASH_STRUCT(type, hash<type>, __VA_ARGS__) \
} \
JPH_SUPPRESS_WARNING_POP
Definition: Reference.h:204

Function Documentation

◆ Hash64()

uint64 Hash64 ( uint64  inValue)
inline

A 64 bit hash function by Thomas Wang, Jan 1997 See: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm

Parameters
inValueValue to hash
Returns
Hash

◆ HashBytes()

JPH_NAMESPACE_BEGIN uint64 HashBytes ( const void *  inData,
uint  inSize,
uint64  inSeed = 0xcbf29ce484222325UL 
)
inline

Implements the FNV-1a hash algorithm

See also
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
Parameters
inDataData block of bytes
inSizeNumber of bytes
inSeedSeed of the hash (can be used to pass in the hash of a previous operation, otherwise leave default)
Returns
Hash

◆ HashCombine()

template<typename... Values>
void HashCombine ( std::size_t &  ioSeed,
Values...  inValues 
)
inline

Hash combiner to use a custom struct in an unordered map or set

Usage:

struct SomeHashKey
{
    std::string key1;
    std::string key2;
    bool key3;
};

JPH_MAKE_HASHABLE(SomeHashKey, t.key1, t.key2, t.key3) 

◆ HashCombineHelper()

template<typename T >
void HashCombineHelper ( size_t &  ioSeed,
const T &  inValue 
)
inline

Helper function that hashes a single value into ioSeed Taken from: https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x.