C++ Unordered_multimap Library - bucket_count() Function


Advertisements

Description

The C++ function std::unordered_multimap::bucket_count() returns the number of buckets present in unordered_multimap container.

Declaration

Following is the declaration for std::unordered_multimap::bucket_count() function form std::unordered_map() header.

C++11

size_type bucket_count() const noexcept;

Parameters

None

Return value

Returns the total number of bucket present in the unordered_multimap.

Exceptions

This member function does not throw exception.

Time complexity

Constant i.e. O(1)

Example

The following example shows the usage of std::unordered_multimap::bucket_count() function.

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm = {
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            {'e', 5}
            };

   cout << "Number of buckets = " << umm.bucket_count() << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Number of buckets = 11
unordered_map.htm
Advertisements