Unordered_multimap ::bucket() es una función incorporada en C++ STL que devuelve el número de depósito en el que se encuentra una clave dada. El tamaño del depósito varía de 0 a bucket_count-1.
Sintaxis:
unordered_multimap_name.bucket(key)
Parámetros: la función acepta una sola clave de parámetro obligatorio que especifica la clave cuyo número de depósito se devolverá.
Valor de retorno: Devuelve un tipo integral sin signo que significa el número de depósito en el que se encuentra la clave.
Los siguientes programas ilustran la función anterior:
Programa 1:
// C++ program to illustrate the // unordered_multimap::bucket() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts key and element sample.insert({ 10, 100 }); sample.insert({ 10, 100 }); sample.insert({ 20, 200 }); sample.insert({ 30, 300 }); sample.insert({ 15, 150 }); // iterate for all elements and print its bucket number for (auto it = sample.begin(); it != sample.end(); it++) { cout << "The bucket number in which {" << it->first << ", " << it->second << "} is " << sample.bucket(it->first) << endl; } return 0; }
Producción:
The bucket number in which {15, 150} is 1 The bucket number in which {30, 300} is 2 The bucket number in which {20, 200} is 6 The bucket number in which {10, 100} is 3 The bucket number in which {10, 100} is 3
Programa 2:
// C++ program to illustrate the // unordered_multimap::bucket() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<char, char> sample; // inserts key and element sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'b' }); sample.insert({ 'b', 'c' }); sample.insert({ 'r', 'a' }); sample.insert({ 'c', 'b' }); // iterate for all elements and print its bucket number for (auto it = sample.begin(); it != sample.end(); it++) { cout << "The bucket number in which {" << it->first << ", " << it->second << "} is " << sample.bucket(it->first) << endl; } return 0; }
Producción:
The bucket number in which {c, b} is 1 The bucket number in which {r, a} is 2 The bucket number in which {b, c} is 0 The bucket number in which {a, b} is 6 The bucket number in which {a, b} is 6