Open In App

unordered_multimap hash_function() in C++ STL

Last Updated : 08 Aug, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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: The function does not accept any parameter.

Return Value: The function returns the hash function.

Below programs illustrate the unordered_multimap::hash_function() function:

Program 1:




// C++ program to illustrate the
// unordered_multimap::hash_function()
#include <iostream>
#include <unordered_map>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multimap<string, string> sample;
  
    // inserts key and elements
    sample.insert({ "gopal", "dave" });
    sample.insert({ "gopal", "dave" });
    sample.insert({ "gopal", "dave" });
    sample.insert({ "geeks", "geeks" });
  
    // use of hash_function
    unordered_multimap<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 << "{" << it->first << ":"
             << it->second << "}, ";
    }
    return 0;
}


Output:

15276750567035005396
Key and Elements: {geeks:geeks}, {gopal:dave}, {gopal:dave}, {gopal:dave},

Program 2:




// C++ program to illustrate the
// unordered_multimap::hash_function()
#include <iostream>
#include <unordered_map>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multimap<string, string> sample;
  
    // insertion of key and elements
    sample.insert({ "gopal", "dave" });
    sample.insert({ "geeks", "geeks" });
  
    // use of hash_function
    unordered_multimap<string, string>::hasher fn
                                      = sample.hash_function();
  
    cout << fn("geeksforgeeks") << endl;
  
    // print the key and elements
    cout << "Key and Elements: ";
    for (auto it = sample.begin(); it != sample.end(); it++) {
        cout << "{" << it->first << ":"
             << it->second << "}, ";
    }
    return 0;
}


Output:

5146686323530302118
Key and Elements: {geeks:geeks}, {gopal:dave},


Similar Reads

unordered_set hash_function() in C++ STL
The unordered_set::hash_function() is a built-in function in C++ STL which is used to get hash function. This hash function is a unary function which takes asingle argument only and returns a unique value of type size_t based on it. Syntax: unordered_set_name.hash_function() Parameter: The function accepts no parameter. Return Value: The function r
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: The function does not accepts any parameter. Ret
1 min read
unordered_map hash_function() function in C++ STL
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:
2 min read
unordered_multimap begin() and end() function in C++ STL
The unordered_multimap::begin() is a built-in function in C++ STL that returns an iterator pointing to the first element in the container or to the first element in one of its buckets. Syntax: unordered_multimap_name.begin(n) Parameters: The function accepts one parameter. If a parameter is passed, it returns an iterator pointing to the first eleme
5 min read
unordered_multimap key_eq() function in C++ STL
unordered_multimap::key_eq() is a built-in function in C++ STL which returns a boolean value according to the comparison. It depends on the key equivalence comparison predicate used by the unordered_multimap container. The key equivalence comparison is a predicate which takes two arguments and returns a boolean value indicating whether they are to
2 min read
unordered_multimap max_bucket_count() function in C++ STL
The unordered_multimap::max_bucket_count() is a built-in function in C++ STL which returns the maximum number of buckets that the unordered multimap container can have. This is the maximum it can have, it cannot exceed despite the collisions due to certain limitations on it. Syntax: unordered_multimap_name.max_bucket_count() Parameter: The function
2 min read
unordered_multimap find() function in C++ STL
The unordered_multimap::find() is a built-in function in C++ STL which returns an iterator which points to one of the elements which has the key k. If the container does not contain any element with key k, then it returns an iterator which points to the position which is past the last element in the container. Syntax: unordered_multimap_name.find(k
3 min read
unordered_multimap load_factor() function in C++ STL
The unordered_multimap::load_factor() is a built-in function in C++ STL which returns returns the current load factor in the unordered_multimap container. The load factor is the ratio between the number of elements in the container (its size) and the number of buckets (bucket_count): load_factor = size / bucket_count The load factor influences the
3 min read
unordered_multimap equal_range() function in C++ STL
unordered_multimap::equal_range() is a built-in function in C++ STL which returns the range in which all the element's key is equal to a key. It returns a pair of iterators where the first is an iterator pointing to the lower bound of the range and second is an iterator pointing to the upper bound of the range. If there is no element equal to a giv
3 min read
unordered_multimap empty() function in C++ STL
The unordered_multimap::empty() is a built-in function in C++ STL which returns a boolean value. It returns true if the unordered_multimap container is empty. Otherwise, it returns false. Syntax: unordered_multimap_name.empty() Parameters: The function does not accept any parameter. Return Value: It returns a boolean value which denotes whether a u
2 min read
Practice Tags :