The unordered_map::bucket() is a built-in STL function in C++ which returns the bucket number where the element with the key k is located in the map.
Syntax:
size_type bucket(key)
Parameter: The function accepts one mandatory parameter key which specifies the key whose bucket number is to be returned.
Return Value: This method returns an unsigned integral type which represents the bucket number of the key k which is passed in the parameter.
Below program illustrate the unordered_map::bucket() function:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<string, string> mymap;
mymap = { { "Australia" , "Canberra" },
{ "U.S." , "Washington" },
{ "France" , "Paris" } };
auto it = mymap.begin();
int number = mymap.bucket(it->first);
cout << "The bucket number of key " << it->first
<< " is " << number;
return 0;
}
|
Output:
The bucket number of key France is 3
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!