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.

Return Value: The function returns the hash function.

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

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

15276750567035005396
geeks2 for geeks1 geeks1

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

5146686323530302118


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.