diff --git a/spot/misc/hash.hh b/spot/misc/hash.hh index 52b603c66..94f603b7c 100644 --- a/spot/misc/hash.hh +++ b/spot/misc/hash.hh @@ -22,6 +22,7 @@ #pragma once +#include #include #include #include @@ -80,11 +81,26 @@ namespace spot template std::size_t operator()(const std::pair &p) const noexcept { - std::hash th; - std::hash uh; - return wang32_hash(static_cast(th(p.first)) ^ - static_cast(uh(p.second))); + if constexpr (std::is_integral::value + && sizeof(T) <= sizeof(std::size_t)/2 + && std::is_integral::value + && sizeof(U) <= sizeof(std::size_t)/2) + { + constexpr unsigned shift = (sizeof(std::size_t)/2)*CHAR_BIT; + std::size_t h = p.first; + h <<= shift; + h += p.second; + return h; + } + else + { + std::hash th; + std::hash uh; + + return wang32_hash(static_cast(th(p.first)) ^ + static_cast(uh(p.second))); + } } };