Fix V3Hash when building -m32

This commit is contained in:
Geza Lore 2021-06-13 20:04:26 +01:00
parent 01a54d6960
commit 0c4d88bacc

View File

@ -26,6 +26,10 @@
class V3Hash final {
uint32_t m_value; // The 32-bit hash value.
inline static uint32_t combine(uint32_t a, uint32_t b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
public:
// CONSTRUCTORS
V3Hash()
@ -34,8 +38,10 @@ public:
: m_value{val} {}
explicit V3Hash(int32_t val)
: m_value{static_cast<uint32_t>(val)} {}
explicit V3Hash(size_t val)
: m_value{static_cast<uint32_t>(val)} {}
explicit V3Hash(uint64_t val)
: m_value{combine(static_cast<uint32_t>(val), static_cast<uint32_t>(val >> 32))} {}
explicit V3Hash(int64_t val)
: m_value{combine(static_cast<uint32_t>(val), static_cast<uint32_t>(val >> 32))} {}
explicit V3Hash(const std::string& val);
// METHODS
@ -48,20 +54,12 @@ public:
bool operator<(const V3Hash& rh) const { return m_value < rh.m_value; }
// '+' combines hashes
V3Hash operator+(const V3Hash& that) const {
return V3Hash(m_value ^ (that.m_value + 0x9e3779b9 + (m_value << 6) + (m_value >> 2)));
template <class T> V3Hash operator+(T that) const {
return V3Hash(combine(m_value, V3Hash(that).m_value));
}
V3Hash operator+(uint32_t value) const { return *this + V3Hash(value); }
V3Hash operator+(int32_t value) const { return *this + V3Hash(value); }
V3Hash operator+(size_t value) const { return *this + V3Hash(value); }
V3Hash operator+(const std::string& value) const { return *this + V3Hash(value); }
// '+=' combines in place
V3Hash& operator+=(const V3Hash& that) { return *this = *this + that; }
V3Hash& operator+=(uint32_t value) { return *this += V3Hash(value); }
V3Hash& operator+=(int32_t value) { return *this += V3Hash(value); }
V3Hash& operator+=(size_t value) { return *this += V3Hash(value); }
V3Hash& operator+=(const std::string& that) { return *this += V3Hash(that); }
template <class T> V3Hash& operator+=(T that) { return *this = *this + that; }
};
std::ostream& operator<<(std::ostream& os, const V3Hash& rhs);