add a hash combine implementation that has some minor performance guarantees
This commit is contained in:
		
							parent
							
								
									31fbf99109
								
							
						
					
					
						commit
						2b2ed50721
					
				| @ -32,13 +32,41 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| 
 | ||||
| #include <functional> | ||||
| 
 | ||||
| // this is largely inspired by boost's hash combine
 | ||||
| template<typename T> | ||||
| inline void hash_combine(std::size_t &seed, const T& val) | ||||
| { | ||||
|     seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline void hash_val(std::size_t &seed, const T& val) | ||||
| { | ||||
|     hash_combine(seed, val); | ||||
| } | ||||
| 
 | ||||
| template<typename T, typename ... Types> | ||||
| inline void hash_val(std::size_t &seed, const T& val, const Types& ... args) | ||||
| { | ||||
|     hash_combine(seed, val); | ||||
|     hash_val(seed, args ...); | ||||
| } | ||||
| 
 | ||||
| template<typename ... Types> | ||||
| inline std::size_t hash_val( const Types&... args) | ||||
| { | ||||
|     std::size_t seed = 0; | ||||
|     hash_val(seed, args...); | ||||
|     return seed; | ||||
| } | ||||
| 
 | ||||
| namespace std | ||||
| { | ||||
| template <> struct hash<std::pair<NodeID, NodeID>> | ||||
| { | ||||
|     size_t operator()(const std::pair<NodeID, NodeID> &pair) const | ||||
|     { | ||||
|         return std::hash<int>()(pair.first) ^ std::hash<int>()(pair.second); | ||||
|         return hash_val(pair.first, pair.second); | ||||
|     } | ||||
| }; | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user