What is the purpose of the equal_to<Key>
function in a boost::unordered_multimap?
In the documentation it says is to determine whether two keys are the same but is not completely clear for me.
My guess is that using the function equal_range
with an input key K, it will retrieve the pairs key, value that are indexed in the corresponding bucket but also whose keys are the same as K according to the equal_to<key>
function.
Please correct me if I'm wrong.
The typename Hash = boost::hash<Key>
template parameter is used to hash the keys to distribute entries into the hash table. However, multiple keys may have the same hash value (a collision). That's why you also need typename Pred = std::equal_to<Key>
: to find the matching key, if any, among all the entries whose keys hashed to the same value.