From c7146f61d00ec4e0254c1fbba96ea3108d563a2d Mon Sep 17 00:00:00 2001 From: Force Charlie Date: Tue, 2 Jul 2019 14:44:54 +0800 Subject: [PATCH] Expand string types for heterogeneous lookups In Windows, it's almost impossible to avoid using wchar_t, so heterogeneous lookups that support std::wstring/std::wstring_view are pretty good. --- parallel_hashmap/phmap.h | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index ce6a7da..3ac0593 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -4014,6 +4014,47 @@ struct HashEq : StringHashEq {}; template <> struct HashEq : StringHashEq {}; + +// support char16_t wchar_t .... +template +struct StringHashT +{ + + using is_transparent = void; + + size_t operator()(std::basic_string_view v) const { + std::string_view bv{reinterpret_cast(v.data()), v.size()*sizeof(CharT)}; + return phmap::Hash{}(bv); + } +}; + +// Supports heterogeneous lookup for basic_string-like elements. +template +struct StringHashEqT +{ + using Hash = StringHashT; + struct Eq { + using is_transparent = void; + bool operator()(std::basic_string_view lhs, std::basic_string_view rhs) const { + return lhs == rhs; + } + }; +}; + +// char16_t +template <> +struct HashEq : StringHashEqT {}; + +template <> +struct HashEq : StringHashEqT {}; + +// wchar_t +template <> +struct HashEq : StringHashEqT {}; + +template <> +struct HashEq : StringHashEqT {}; + #endif // Supports heterogeneous lookup for pointers and smart pointers.