Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ unordered_multiset::hash_function function is used to return 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.

Syntax

hasher hash_function() const;

Parameters

No parameter is required.

Return Value

The hash function.

Time Complexity

Constant i.e, Θ(1)

Example:

The below example 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