Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand string types for heterogeneous lookups #15

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions parallel_hashmap/phmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,47 @@ struct HashEq<std::string> : StringHashEq {};
template <>
struct HashEq<std::string_view> : StringHashEq {};


// support char16_t wchar_t ....
template<class CharT>
struct StringHashT
{

using is_transparent = void;

size_t operator()(std::basic_string_view<CharT> v) const {
std::string_view bv{reinterpret_cast<const char*>(v.data()), v.size()*sizeof(CharT)};
return phmap::Hash<std::string_view>{}(bv);
}
};

// Supports heterogeneous lookup for basic_string<T>-like elements.
template<class CharT>
struct StringHashEqT
{
using Hash = StringHashT<CharT>;
struct Eq {
using is_transparent = void;
bool operator()(std::basic_string_view<CharT> lhs, std::basic_string_view<CharT> rhs) const {
return lhs == rhs;
}
};
};

// char16_t
template <>
struct HashEq<std::u16string> : StringHashEqT<char16_t> {};

template <>
struct HashEq<std::u16string_view> : StringHashEqT<char16_t> {};

// wchar_t
template <>
struct HashEq<std::wstring> : StringHashEqT<wchar_t> {};

template <>
struct HashEq<std::wstring_view> : StringHashEqT<wchar_t> {};

#endif

// Supports heterogeneous lookup for pointers and smart pointers.
Expand Down