hash_map::max_load_factor (STL/CLR)
取得或設定最大元素每個 Bucket。
float max_load_factor();
void max_load_factor(float new_factor);
參數
- new_factor
要儲存的新的最大的負載荷因素。
備註
第一成員函式傳回目前儲存的最大的負載荷因素。 您會用它來判斷最大平均 Bucket 大小。
第二個成成員函式以 new_factor取代存放的最大的負載荷因素。 自動重新雜湊不會發生在後續插入之前。
範例
// cliext_hash_map_max_load_factor.cpp
// compile with: /clr
#include <cliext/hash_map>
typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
{
Myhash_map c1 = gcnew Myhash_map;
c1.insert(Myhash_map::make_value(L'a', 1));
c1.insert(Myhash_map::make_value(L'b', 2));
c1.insert(Myhash_map::make_value(L'c', 3));
// display contents " [a 1] [b 2] [c 3]"
for each (Myhash_map::value_type elem in c1)
System::Console::Write(" [{0} {1}]", elem->first, elem->second);
System::Console::WriteLine();
// inspect current parameters
System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
System::Console::WriteLine("max_load_factor() = {0}",
c1.max_load_factor());
System::Console::WriteLine();
// change max_load_factor and redisplay
c1.max_load_factor(0.25f);
System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
System::Console::WriteLine("max_load_factor() = {0}",
c1.max_load_factor());
System::Console::WriteLine();
// rehash and redisplay
c1.rehash(100);
System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
System::Console::WriteLine("max_load_factor() = {0}",
c1.max_load_factor());
return (0);
}
需求
標頭: <cliext/hash_map>
命名空間: cliext
請參閱
參考
hash_map::bucket_count (STL/CLR)