Unordered_multimap ::bucket_size() es una función integrada en C++ STL que devuelve la cantidad de elementos en el depósito n.
Sintaxis:
unordered_multimap_name.bucket_size(n)
Parámetros: la función acepta un parámetro n que especifica el número de depósito cuyo recuento se devolverá.
Valor devuelto: Devuelve un tipo integral sin signo que denota el número de elementos en el cubo con el número de cubo n.
Los siguientes programas ilustran la función anterior:
Programa 1:
// C++ program to illustrate the // unordered_multimap::bucket_size() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts element sample.insert({ 10, 100 }); sample.insert({ 10, 100 }); sample.insert({ 20, 200 }); sample.insert({ 30, 300 }); sample.insert({ 15, 150 }); cout << "The total count of buckets: " << sample.bucket_count(); // prints all element bucket wise for (int i = 0; i < sample.bucket_count(); i++) { cout << "\nNumber of elements in Bucket " << i << " = " << sample.bucket_size(i); } return 0; }
Producción:
The total count of buckets: 7 Number of elements in Bucket 0 = 0 Number of elements in Bucket 1 = 1 Number of elements in Bucket 2 = 1 Number of elements in Bucket 3 = 2 Number of elements in Bucket 4 = 0 Number of elements in Bucket 5 = 0 Number of elements in Bucket 6 = 1
Programa 2:
// C++ program to illustrate the // unordered_multimap::bucket_size() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<char, char> sample; // inserts element sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'b' }); sample.insert({ 'b', 'c' }); sample.insert({ 'r', 'a' }); sample.insert({ 'c', 'b' }); cout << "The total count of buckets: " << sample.bucket_count(); // prints all element bucket wise for (int i = 0; i < sample.bucket_count(); i++) { cout << "\nNumber of elements in Bucket " << i << " = " << sample.bucket_size(i); } return 0; }
Producción:
The total count of buckets: 7 Number of elements in Bucket 0 = 1 Number of elements in Bucket 1 = 1 Number of elements in Bucket 2 = 1 Number of elements in Bucket 3 = 0 Number of elements in Bucket 4 = 0 Number of elements in Bucket 5 = 0 Number of elements in Bucket 6 = 2