diff --git a/BAN/include/BAN/StringView.h b/BAN/include/BAN/StringView.h index 47e0fcab..40f8d850 100644 --- a/BAN/include/BAN/StringView.h +++ b/BAN/include/BAN/StringView.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -222,6 +223,25 @@ namespace BAN size_type m_size = 0; }; + template<> + struct hash + { + hash_t operator()(StringView string) const + { + constexpr hash_t FNV_offset_basis = 0x811c9dc5; + constexpr hash_t FNV_prime = 0x01000193; + + hash_t hash = FNV_offset_basis; + for (StringView::size_type i = 0; i < string.size(); i++) + { + hash *= FNV_prime; + hash ^= (uint8_t)string[i]; + } + + return hash; + } + }; + } inline constexpr BAN::StringView operator""_sv(const char* str, BAN::StringView::size_type len) { return BAN::StringView(str, len); }