Last Updated : 02 Aug, 2018
The
unordered_multiset::hash_function()is a built-in function in C++ STL which is used to get the hash function. This hash function is a unary function which takes a single argument only and returns a unique value of type size_t based on it.
Syntax:
unordered_multiset_name.hash_function()Parameter
: The function does not accepts any parameter.
Return Value: The function returns the hash function. Below programs illustrate the
unordered_multiset::hash_function()function:
Program 1:
CPP
// CPP program to illustrate the
// unordered_multiset::hash_function() function
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
int main()
{
unordered_multiset<string> sampleSet = { "geeks1", "geeks1", "for", "geeks2" };
// use of hash_function
unordered_multiset<string>::hasher fn = sampleSet.hash_function();
cout << fn("geeks") << endl;
for (auto it = sampleSet.begin(); it != sampleSet.end(); it++) {
cout << *it << " ";
}
cout << endl;
return 0;
}
Output:
15276750567035005396 geeks2 for geeks1 geeks1Program 2
:
CPP
// CPP program to illustrate the
// unordered_multiset::hash_function () function
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
int main()
{
unordered_multiset<string> sampleSet;
// use of hash_function
unordered_multiset<string>::hasher fn = sampleSet.hash_function();
cout << fn("geeksforgeeks") << endl;
return 0;
}
Output:
5146686323530302118
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4