Jlm
Hash.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_UTIL_HASH_HPP
7 #define JLM_UTIL_HASH_HPP
8 
9 #include <functional>
10 #include <string_view>
11 
12 namespace jlm::util
13 {
14 
18 template<typename T>
19 struct Hash : std::hash<T>
20 {
21 };
22 
23 template<typename First, typename Second>
24 struct Hash<std::pair<First, Second>>
25 {
26  std::size_t
27  operator()(const std::pair<First, Second> & value) const noexcept
28  {
29  return Hash<First>()(value.first) ^ Hash<Second>()(value.second) << 1;
30  }
31 };
32 
43 template<typename... Args>
44 void
45 combineHashesWithSeed(std::size_t & seed, std::size_t hash, Args... args)
46 {
47  seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
48  (combineHashesWithSeed(seed, args), ...);
49 }
50 
61 template<typename... Args>
62 std::size_t
63 CombineHashes(std::size_t hash, Args... args)
64 {
65  std::size_t seed = 0;
66  combineHashesWithSeed(seed, hash, std::forward<Args>(args)...);
67  return seed;
68 }
69 
70 }
71 
72 #endif
void combineHashesWithSeed(std::size_t &seed, std::size_t hash, Args... args)
Definition: Hash.hpp:45
std::size_t CombineHashes(std::size_t hash, Args... args)
Definition: Hash.hpp:63
std::size_t operator()(const std::pair< First, Second > &value) const noexcept
Definition: Hash.hpp:27