From b36ed23f6e2ec371e8b085442d054bd5434a942a Mon Sep 17 00:00:00 2001 From: paulfd Date: Fri, 30 Aug 2019 10:26:13 +0200 Subject: [PATCH] Simplified the hash helper so that it's purely based on string views --- sources/Helpers.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sources/Helpers.h b/sources/Helpers.h index e7d3a621..73da79bc 100644 --- a/sources/Helpers.h +++ b/sources/Helpers.h @@ -22,11 +22,11 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once -#include #include #include #include #include + #ifdef HAVE_X86INTRIN_H #include #endif @@ -60,17 +60,13 @@ inline std::string_view trim(std::string_view s) return s; } -inline constexpr unsigned int Fnv1aBasis = 0x811C9DC5; -inline constexpr unsigned int Fnv1aPrime = 0x01000193; -inline constexpr unsigned int hash(const char* s, unsigned int h = Fnv1aBasis) -{ - return !*s ? h : hash(s + 1, static_cast((h ^ *s) * static_cast(Fnv1aPrime))); -} +inline constexpr uint64_t Fnv1aBasis = 0x811C9DC5; +inline constexpr uint64_t Fnv1aPrime = 0x01000193; -inline unsigned int hash(std::string_view s, unsigned int h = Fnv1aBasis) +inline constexpr uint64_t hash(std::string_view s, uint64_t h = Fnv1aBasis) { if (s.length() > 0) - return hash(std::string_view(s.data() + 1, s.length() - 1), static_cast((h ^ s.front()) * static_cast(Fnv1aPrime))); + return hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ); return h; }