unordered_set hash_function() in C++

hash_function(): This function is available in the File: unordered_set.h. This function is a build-in function in STL of C++.

Syntax:

std::hash<int> std::unordered_set<int>::hash_function() const

This function returns the hash functor object with which the unordered_set was constructed.

Parameters: NA

File: unordered_set.h

Returns: Returns the hash function object used by the unordered_set container.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    unordered_set<stringst = {"Hello""C++""Program"
"World""Code"};

    unordered_set<string>::hasher hash = st.hash_function();

    cout << hash("Hello") << "\n";

    cout << hash("C++") << "\n";

    return 0;
}


Output:

2275118702903107253 15518724754199266856


No comments:

Post a Comment