public member function
<unordered_set>

std::unordered_multiset::bucket_count

size_type bucket_count() const noexcept;
Return number of buckets
Returns the number of buckets in the unordered_multiset container.

A bucket is a slot in the container's internal hash table to which elements are assigned based on their hash value.

The number of buckets influences directly the load factor of the container's hash table (and thus the probability of collision). The container automatically increases the number of buckets to keep the load factor below a specific threshold (its max_load_factor), causing a rehash each time the number of buckets needs to be increased.

Parameters

none

Return Value

The current amount of buckets.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// unordered_multiset::bucket_count
#include <iostream>
#include <string>
#include <unordered_set>

int main ()
{
  std::unordered_multiset<std::string> myums =
  {"Klingon","Vulcan","Klingon","Cardassian","Vulcan","Human"};

  unsigned n = myums.bucket_count();

  std::cout << "myums has " << n << " buckets.\n";

  for (unsigned i=0; i<n; ++i) {
    std::cout << "bucket #" << i << " contains:";
    for (auto it = myums.begin(i); it!=myums.end(i); ++it)
      std::cout << " " << *it;
    std::cout << "\n";
  }

  return 0;
}


Possible output:
myums has 7 buckets.
bucket #0 contains: Vulcan Vulcan
bucket #1 contains: 
bucket #2 contains: 
bucket #3 contains: Cardassian
bucket #4 contains: 
bucket #5 contains: Human Klingon Klingon
bucket #6 contains: 

Complexity

Constant.

Iterator validity

No changes.

See also

  • 997351548 2018-02-20
  • 903691547 2018-02-20
  • 9127171546 2018-02-20
  • 2234751545 2018-02-20
  • 1685381544 2018-02-20
  • 911091543 2018-02-20
  • 9281021542 2018-02-20
  • 632231541 2018-02-20
  • 9751491540 2018-02-20
  • 8333621539 2018-02-20
  • 995001538 2018-02-20
  • 6477441537 2018-02-20
  • 511981536 2018-02-19
  • 2072881535 2018-02-19
  • 6024461534 2018-02-19
  • 7594061533 2018-02-19
  • 9311341532 2018-02-19
  • 4928331531 2018-02-19
  • 38561530 2018-02-19
  • 7776611529 2018-02-19