17#ifndef AGX_HASHFUNCTIONS_H
18#define AGX_HASHFUNCTIONS_H
69 x += 0x9e3779b97f4a7c15ULL;
70 x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
71 x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
78 UInt64 h = 0x9e3779b97f4a7c15ULL;
79 h = ( h ^
splitMix64( x ) ) * 0xbf58476d1ce4e5b9ULL;
80 h = ( h ^
splitMix64( y ) ) * 0x94d049bb133111ebULL;
87 const auto h =
hash64( x, y, z );
88 return static_cast<UInt32>( h ^ ( h >> 32 ) );
100 static constexpr double dInt64Max = (double)std::numeric_limits<Int64>::max();
101 static constexpr double dInt64Min = (double)std::numeric_limits<Int64>::min();
103 if ( eps < 1.0E-14 ) {
105 std::memcpy( &result, &x,
sizeof(
UInt64 ) );
109 const double t = x / eps;
111 return static_cast<UInt64>( std::numeric_limits<Int64>::max() );
112 else if ( t < dInt64Min )
113 return static_cast<UInt64>( std::numeric_limits<Int64>::min() );
115 return static_cast<UInt64>(
static_cast<Int64>( std::floor( t ) ) );
135 template<
typename Vec3Type,
class Epsilon = std::ratio<1, 1'000'000>>
138 static constexpr double CellSize = (double)Epsilon::num / Epsilon::den;
151 const UInt32 p1 = 73856093UL;
152 const UInt32 p2 = 19349663UL;
153 const UInt32 p3 = 83492791UL;
155 return (p1 * x) ^ (p2 * y) ^ (p3 * z);
173 return h1 ^ (h2 + 0x9e3779b9 + (h1<<6) + (h1>>2));
176 template<
typename T1,
typename T2>
183 template<
typename T1,
typename T2>
199 key = ~key + (key << 15);
200 key = key ^ (key >> 12);
201 key = key + (key << 2);
202 key = key ^ (key >> 4);
204 key = key ^ (key >> 16);
224 key = (~key) + (key << 18);
225 key = key ^ (key >> 31);
227 key = key ^ (key >> 11);
228 key = key + (key << 6);
229 key = key ^ (key >> 22);
246 struct HashFn<size_t>
276 UInt32 hashValue = startValue;
278 for (
UInt32 i = 0; i < key.length(); i++)
279 hashValue = 37 * hashValue + (
UInt32)key[i];
310 hashValue = 37 * hashValue + (
UInt32)(*key++);
318 return strcmp(key1, key2) == 0;
323 return strcmp(key1, key2) == 0;
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
UInt32 hash(const T &key)
UInt32 stringHash(const T &key, UInt32 startValue=0)
AGXCORE_EXPORT void splitHashKey(agx::UInt64 key, agx::UInt32 &id1, agx::UInt32 &id2)
UInt64 splitMix64(UInt64 x)
SplitMix64 pulls entropy from the high 32 bits to the low, which preserves more uniqueness performing...
AGXCORE_EXPORT agx::UInt64 buildHashKey(agx::UInt32 id1, agx::UInt32 id2)
UInt64 hash64(UInt64 x, UInt64 y, UInt64 z)
UInt64 spatialHash(double x, double eps)
Hash function suitable for spatial hashing with configurable grid spacing eps.
bool hashKeyEqual(const T1 &key1, const T2 &key2)
UInt64 spatialHash64(double x, double y, double z, double eps)
AGXCORE_EXPORT bool hashKeyContains(agx::UInt64 key, agx::UInt32 id)
UInt32 operator()(Int32 key) const
UInt32 operator()(Int64 key) const
UInt32 operator()(const String &key) const
UInt32 operator()(const PtrT key) const
UInt32 operator()(UInt32 key) const
UInt32 operator()(UInt64 key) const
UInt32 operator()(const char *key) const
UInt32 operator()(const std::pair< T1, T2 > &key) const
UInt32 operator()(const std::string &key) const
UInt32 operator()(const T &key) const
Spatial hashing of 3D vector types with default grid size 1.0E-6.
UInt32 operator()(const Vec3Type &v) const
static constexpr double CellSize