C++ Standard Library C++ STL Library

C++ unordered_multiset - hash_function() Function

The C++ unordered_multiset::hash_function function returns the hash function object used by the unordered_multiset container. The hash function is unary function which takes key_type object as argument and returns unique value of type size_t based on it.


hasher hash_function() const;


No parameter is required.

Return Value

The hash function.

Time Complexity

Constant i.e, Θ(1)


The example below shows the usage of unordered_multiset::hash_function().

#include <iostream>
#include <unordered_set>
using namespace std;
int main (){
  unordered_multiset<string> uMSet;

  unordered_multiset<string>::hasher hfun = uMSet.hash_function();

  cout<<"The hash function for alpha: "<<hfun("alpha")<<"\n";
  cout<<"The hash function for Alpha: "<<hfun("Alpha")<<"\n";

  return 0;

The output of the above code will be:

The hash function for alpha: 6998202458872244694
The hash function for Alpha: 6500479057991640117

❮ C++ <unordered_set> Library