serge-sans-paille/frozen

Hashing with Boost Hash Library

staticassert opened this issue · 2 comments

Is there a method to use the boost hash library as a hash function in frozen::unordered_map?

I have been using boost::hash in std::unordered_map to work with non-integral keys. Using boost::hash in frozen::unordered_map creates error, because the pmh_table::lookup() function applies 2 parameters: key and static_cast<size_t>(first_seed_), whereas boost::hash only accepts 1 parameter. Is there a workaround for this?

This is the error:
function "boost::hash<T>::operator() [with T=std::__1::pair<int, int>]" cannot be called with the given argument list -- argument types are: (const std::__1::pair<int, int>, <error-type>) -- object type is: const boost::hash<std::__1::pair<int, int>> -- detected during: -- instantiation of "size_t frozen::bits::pmh_tables<M, Hasher>::lookup(const KeyType &key) const [with M=64UL, Hasher=boost::hash<std::__1::pair<int, int>>, KeyType=std::__1::pair<int, int>]" at line 120 of "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/frozen/unordered_map.h" -- instantiation of "const Value &frozen::unordered_map<Key, Value, N, Hash, KeyEqual>::at(const Key &key) const [with Key=std::__1::pair<int, int>, Value=char, N=64UL, Hash=boost::hash<std::__1::pair<int, int>>, KeyEqual=std::__1::equal_to<std::__1::pair<int, int>>]" at line 193 of "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/frozen/unordered_map.h"

... the pmh_table::lookup() function applies 2 parameters: key and static_cast<size_t>(first_seed_), whereas boost::hash only accepts 1 parameter.
Is there a workaround for this?

No: this library completely relies on the ability to select alternate seeds in order to avoid hash collisions. To my understanding this is the whole point of a "perfect hash function": to avoid hash collisions requiring buckets that need to be searched in some different fashion (usually linearly).