Line data Source code
1 : #ifndef D1BF7155_C5F8_4887_9905_50C52859681F_HPP 2 : #define D1BF7155_C5F8_4887_9905_50C52859681F_HPP 3 : 4 : #include <string> 5 : #include <type_traits> 6 : #include <utility> 7 : 8 : namespace cell 9 : { 10 : 11 : // https://stackoverflow.com/a/2595226 12 62 : template <class T> inline void hashCombine(std::size_t& seed, const T& v) 13 : { 14 : std::hash<T> hasher; 15 62 : seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 16 62 : } 17 : 18 : /** 19 : * @returns a well-mixed combined hash for 2 values 20 : */ 21 31 : template <typename T1, typename T2> std::size_t calculateHash(const T1& a, const T2& b) 22 : { 23 31 : std::size_t seed = 0; 24 31 : hashCombine(seed, a); 25 31 : hashCombine(seed, b); 26 : 27 31 : return seed; 28 : } 29 : 30 : /** 31 : * @brief A generic pair hasher using std::hash and the boost method for mixing 2 hash values 32 : */ 33 : struct PairHasher 34 : { 35 31 : template <typename T1, typename T2> std::size_t operator()(const std::pair<T1, T2>& pair) const 36 : { 37 31 : return calculateHash(pair.first, pair.second); 38 : } 39 : }; 40 : 41 : } // namespace cell 42 : 43 : #endif /* D1BF7155_C5F8_4887_9905_50C52859681F_HPP */