hash_map::rehash (STL/CLR)

重新生成哈希表。

    void rehash();

备注

成员函数重新生成哈希表,确保该() <= hash_map::load_factor (STL/CLR)hash_map::max_load_factor (STL/CLR)。 否则,此哈希表的尺寸增大仅根据需要在插入后。(为固定大小决不自动会降低。)使用哈希来调整表的大小。

示例

// cliext_hash_map_rehash.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 (STL/CLR)

hash_map::bucket_count (STL/CLR)

hash_map::load_factor (STL/CLR)

hash_map::max_load_factor (STL/CLR)