Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:12

0001 #ifndef FWCore_Utilities_hash_combine_h
0002 #define FWCore_Utilities_hash_combine_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Utilities
0006 // Class  :     hash_combine
0007 //
0008 /**\function hash_combine hash_combine.h "FWCore/Utilities/interface/hash_combine.h"
0009 
0010  Description: Convenience Functions to Combine Hash Values
0011 
0012  Based on http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3876.pdf
0013  Combination algorithm is the same as boost::hash_combine
0014 
0015  Usage:
0016     <usage>
0017 
0018 */
0019 
0020 // system include files
0021 #include <functional>
0022 
0023 namespace edm {
0024   template <typename T>
0025   inline void hash_combine(std::size_t& seed, const T& val) {
0026     seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
0027   }
0028 
0029   template <typename T, typename... Types>
0030   inline void hash_combine(std::size_t& seed, const T& val, const Types&... args) {
0031     hash_combine(seed, val);
0032     hash_combine(seed, args...);
0033   }
0034 
0035   template <typename... Types>
0036   inline std::size_t hash_value(const Types&... args) {
0037     std::size_t seed{0};
0038     hash_combine(seed, args...);
0039     return seed;
0040   }
0041 
0042 }  // namespace edm
0043 #endif