GeezerVison is showing cpprefjp.github.io — std::unordered_multiset::rehash - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<unordered_set>
std:: unordered_multiset:: rehash (C++11)
void rehash ( size_type n ); // (1) C++11
constexpr void rehash ( size_type n ); // (1) C++26
概要
コンテナのバケット数が最小でも引数 n で指定された値になるように調整(リハッシュ)する。
事後条件
bucket_count () > size () / max_load_factor () かつ、bucket_count () >= n。
戻り値
なし
例外
ハッシュ関数、および、キー比較用関数以外から例外が投げられた場合、コンテナは変更されない。
計算量
平均的なケースでは size () に比例するが、最悪のケースでは size () の 2 乗に比例する。
備考
例
#include <iostream>
#include <unordered_set>
int main ()
{
std :: unordered_multiset < int > ums { 1 , 2 , 3 , 4 , 5 , 6 , 1 , 2 , 3 , 4 , 5 , 6 , };
std::cout << "size is " << ums.size() << ", max_load_factor is " << ums.max_load_factor() << std::endl ;
std::cout << "bucket_count is " << ums.bucket_count() << std::endl ;
// 現在のバケット数より大きな値を指定する。
ums . rehash ( 100 );
std::cout << "bucket_count is " << ums.bucket_count() << std::endl ;
// 現在の要素数 / max_load_factor() よりは大きく、現在のバケット数よりは小さい値を指定する。
ums . rehash ( 20 );
std::cout << "bucket_count is " << ums.bucket_count() << std::endl ;
// 現在の要素数 / max_load_factor() より小さい値を指定する。
ums . rehash ( 1 );
std::cout << "bucket_count is " << ums.bucket_count() << std::endl ;
}
出力例
size is 12, max_load_factor is 1
bucket_count is 23
bucket_count is 101
bucket_count is 23
bucket_count is 13
バージョン
言語
処理系
関連項目
参照