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.

Classes

struct  Hash< T >
 Fallback hash function that calls T::GetHash() More...
 
struct  Hash< float >
 A hash function for floats. More...
 
struct  Hash< double >
 A hash function for doubles. More...
 
struct  Hash< const char * >
 A hash function for character pointers. More...
 
struct  Hash< std::string_view >
 A hash function for std::string_view. More...
 
struct  Hash< String >
 A hash function for String. More...
 
struct  Hash< T * >
 A fallback function for generic pointers. More...
 

Macros

#define JPH_DEFINE_TRIVIAL_HASH(type)
 Helper macro to define a hash function for trivial types.
 
#define JPH_MAKE_HASH_STRUCT(type, name, ...)
 
#define JPH_MAKE_STD_HASH(type)
 
#define JPH_MAKE_HASHABLE(type, ...)
 

Functions

JPH_NAMESPACE_BEGIN uint64 HashBytes (const void *inData, uint inSize, uint64 inSeed=0xcbf29ce484222325UL)
 
constexpr uint64 HashString (const char *inString, uint64 inSeed=0xcbf29ce484222325UL)
 
uint64 Hash64 (uint64 inValue)
 
template<typename T >
void HashCombine (uint64 &ioSeed, const T &inValue)
 Commonly used types.
 
template<typename FirstValue , typename... Values>
uint64 HashCombineArgs (const FirstValue &inFirstValue, Values... inValues)
 

Macro Definition Documentation

◆ JPH_DEFINE_TRIVIAL_HASH

#define JPH_DEFINE_TRIVIAL_HASH (   type)
Value:
template <> \
struct Hash<type> \
{ \
uint64 operator () (const type &inValue) const \
{ \
return HashBytes(&inValue, sizeof(inValue)); \
} \
};
std::uint64_t uint64
Definition Core.h:485
JPH_NAMESPACE_BEGIN uint64 HashBytes(const void *inData, uint inSize, uint64 inSeed=0xcbf29ce484222325UL)
Definition HashCombine.h:15
Fallback hash function that calls T::GetHash()
Definition HashCombine.h:59
uint64 operator()(const T &inValue) const
Definition HashCombine.h:60

Helper macro to define a hash function for trivial types.

◆ JPH_MAKE_HASH_STRUCT

#define JPH_MAKE_HASH_STRUCT (   type,
  name,
  ... 
)
Value:
struct [[nodiscard]] name \
{ \
::JPH::uint64 operator()(const type &t) const \
{ \
return ::JPH::HashCombineArgs(__VA_ARGS__); \
} \
};

◆ JPH_MAKE_HASHABLE

#define JPH_MAKE_HASHABLE (   type,
  ... 
)
Value:
JPH_SUPPRESS_WARNING_PUSH \
JPH_SUPPRESS_WARNINGS \
namespace JPH \
{ \
template<> \
JPH_MAKE_HASH_STRUCT(type, Hash<type>, __VA_ARGS__) \
} \
JPH_SUPPRESS_WARNING_POP \
JPH_MAKE_STD_HASH(type)

◆ JPH_MAKE_STD_HASH

#define JPH_MAKE_STD_HASH (   type)
Value:
JPH_SUPPRESS_WARNING_PUSH \
JPH_SUPPRESS_WARNINGS \
namespace std \
{ \
template<> \
struct [[nodiscard]] hash<type> \
{ \
size_t operator()(const type &t) const \
{ \
return size_t(::JPH::Hash<type>{ }(t)); \
} \
}; \
} \
JPH_SUPPRESS_WARNING_POP
Definition Array.h:590

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 T >
void HashCombine ( uint64 ioSeed,
const T &  inValue 
)
inline

Commonly used types.

Helper function that hashes a single value into ioSeed Based on https://github.com/jonmaiga/mx3 by Jon Maiga

◆ HashCombineArgs()

template<typename FirstValue , typename... Values>
uint64 HashCombineArgs ( const FirstValue &  inFirstValue,
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) 

◆ HashString()

constexpr uint64 HashString ( const char *  inString,
uint64  inSeed = 0xcbf29ce484222325UL 
)
constexpr