C++ Unordered_set Library - rehash



Description

It is used to sets the number of buckets in the container to n or more.

Declaration

Following is the declaration for std::unordered_set::rehash.

C++11

void rehash ( size_type n );

Parameters

n − n is the minimum number of buckets.

Return value

none

Exceptions

Exception is thrown if any element comparison object throws exception.

Please note that invalid arguments cause undefined behavior.

Time complexity

constant time.

Example

The following example shows the usage of std::unordered_set::max_load_factor.

#include <iostream>
#include <string>
#include <unordered_set>

int main () {
   std::unordered_set<std::string> myset;

   myset.rehash(12);

   myset.insert("android");
   myset.insert("java");
   myset.insert("html");
   myset.insert("css");
   myset.insert("javascript");

   std::cout << "current bucket_count: " << myset.bucket_count() << std::endl;

   return 0;
}

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

current bucket_count: 13
unordered_set.htm
Advertisements