blob: 26b633487b7f80ce70434cfaed403399777929f4 [file] [log] [blame]
From 0c4d88baccd3d253479ac94f444b0f3c621807a2 Mon Sep 17 00:00:00 2001
From: Geza Lore <gezalore@gmail.com>
Date: Sun, 13 Jun 2021 20:04:26 +0100
Subject: [PATCH] Fix V3Hash when building -m32
---
src/V3Hash.h | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/V3Hash.h b/src/V3Hash.h
index b28b3bf1..06223567 100644
--- a/src/V3Hash.h
+++ b/src/V3Hash.h
@@ -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);
--
2.32.0