次の方法で共有


hash_multimap::bucket_count (STL/CLR)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at hash_multimap::bucket_count (STL/CLR).

Counts the number of buckets.

Syntax

int bucket_count();  

Remarks

The member functions returns the current number of buckets. You use it to determine the size of the hash table.

Example

// cliext_hash_multimap_bucket_count.cpp   
// compile with: /clr   
#include <cliext/hash_map>   
  
typedef cliext::hash_multimap<wchar_t, int> Myhash_multimap;   
int main()   
    {   
    Myhash_multimap c1 = gcnew Myhash_multimap;   
    c1.insert(Myhash_multimap::make_value(L'a', 1));   
    c1.insert(Myhash_multimap::make_value(L'b', 2));   
    c1.insert(Myhash_multimap::make_value(L'c', 3));   
  
// display contents " [a 1] [b 2] [c 3]"   
    for each (Myhash_multimap::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);   
    }  
  
 [a 1] [b 2] [c 3]  
bucket_count
() = 16  
load_factor
() = 0.1875  
max_load_factor
() = 4  
  
bucket_count
() = 16  
load_factor
() = 0.1875  
max_load_factor
() = 0.25  
  
bucket_count
() = 128  
load_factor
() = 0.0234375  
max_load_factor
() = 0.25  

Requirements

Header: <cliext/hash_map>

Namespace: cliext

See Also

hash_multimap (STL/CLR)
hash_multimap::load_factor (STL/CLR)
hash_multimap::max_load_factor (STL/CLR)