martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.5k stars 143 forks source link

Support Heterogenous Lookup (was: is_transparent_tag) #39

Closed tuket closed 4 years ago

tuket commented 5 years ago

I see there is a version of find that takes is_transparent_tag a parameter. What is it for?

Thanks

martinus commented 5 years ago

The idea was to provide heterogenous lookup.

Here is the problem: Say you have e.g. a robin_hood::unordered_map<std::string, int>, and you want to perform lookups but have only e.g. a std::string_view. With the standard interface you need to create a new std::string that's a copy of the std::string_view content to perform the lookup. That's quite a lot of overhead.

The idea is that with is_transparent_tag you create a robin_hood::unordered_map<std::string, int, robin_hood::hash<>, std::equal_to<>> map, and then you can do a lookup with a stringview that can directly hash the stringview and does not need to create a temporary copy.

The interface is currently not working though, because due to lots of refactoring this doesn't work any more. I need to update this.

More info here: https://abseil.io/tips/144 and here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0919r1.html

I'll leave your question open until I have proper support for this, thanks for reminding me!

martinus commented 4 years ago

Latest paper: "Refinement Proposal for P0919 Heterogeneous lookup for unordered containers" http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1690r0.html

shooshx commented 2 years ago

you create a robin_hood::unordered_map<std::string, int, robin_hood::hash<>, std::equal_to<>> map

Do you mind explaining how this works? It doesn't look like robin_hood::hash has is_transparent like std::equal_to has