unordered_map hash_function() function in C++ STL Last Updated : 17 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The unordered_map::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_map_name.hash_function() Parameter: The function does not accept any parameter. Return Value: The function returns the hash function. Time complexity: Time Complexity of this function is constant O(1). Below programs illustrate the unordered_map::hash_function() function. Example 1 CPP // C++ program to illustrate the // unordered_map::hash_function() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_map<string, string> sample; // inserts key and elements sample.insert({ "Ankit", "MNNIT" }); sample.insert({ "Ram", "MNNIT" }); sample.insert({ "Manoj", "Trichy" }); sample.insert({ "geeks", "geeks" }); // use of hash_function unordered_map<string, string>::hasher fn = sample.hash_function(); cout << fn("geeks") << endl; // print the key and elements cout << "Key and Elements: "; for (auto it = sample.begin(); it != sample.end(); it++) { cout << "\n{" << it->first << ":" << it->second << "}, "; } return 0; } Output: 15276750567035005396 Key and Elements: {geeks:geeks}, {Manoj:Trichy}, {Ankit:MNNIT}, {Ram:MNNIT}, Example 2 CPP // C++ program to illustrate the // unordered_map::hash_function() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_map<int, int> sample; // inserts key and elements sample.insert({ 1, 5 }); sample.insert({ 2, 6 }); sample.insert({ 3, 6 }); sample.insert({ 4, 7 }); // use of hash_function unordered_map<int, int>::hasher fn = sample.hash_function(); cout << fn(4) << endl; // print the key and elements cout << "Key and Elements: "; for (auto it = sample.begin(); it != sample.end(); it++) { cout << "\n{" << it->first << ":" << it->second << "}, "; } return 0; } Output: 4 Key and Elements: {4:7}, {3:6}, {1:5}, {2:6}, Comment More infoAdvertise with us Next Article unordered_multimap hash_function() in C++ STL A ankit15697 Follow Improve Article Tags : Technical Scripter C++ cpp-unordered_map cpp-unordered_map-functions Practice Tags : CPP Similar Reads unordered_multiset hash_function() function in C++ STL 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 1 min read unordered_multiset hash_function() function in C++ STL 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 1 min read unordered_multimap hash_function() in C++ STL The unordered_multimap::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_multimap_name.hash_function() Parameter 2 min read unordered_multimap hash_function() in C++ STL The unordered_multimap::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_multimap_name.hash_function() Parameter 2 min read unordered_map end( ) function in C++ STL The unordered_map::end() is a built-in function in C++ STL which returns an iterator pointing to the position past the last element in the container in the unordered_map container. In an unordered_map object, there is no guarantee that which specific element is considered its first element. But all 3 min read unordered_map end( ) function in C++ STL The unordered_map::end() is a built-in function in C++ STL which returns an iterator pointing to the position past the last element in the container in the unordered_map container. In an unordered_map object, there is no guarantee that which specific element is considered its first element. But all 3 min read Like