当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ unordered_multiset max_load_factor()用法及代码示例


unordered_multiset::max_load_factor()是C++ STL中的内置函数,该函数返回unordered_multiset容器的最大加载因子。此函数还提供设置最大负载系数的选项。

用法(返回最大负载系数):

unordered_multiset_name.max_load_factor()

参数:该函数不接受任何参数。


返回值:它返回一个整数值,该值表示容器的最大负载系数。

以下示例程序旨在说明unordered_multiset::max_load_factor()函数:

程序1

// C++ program to illustrate 
// unordered_multiset::max_load_factor() 
#include <iostream> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
    // declaration 
    unordered_multiset<char> s1; 
    s1 = { 'a', 'b', 'c', 'd' }; 
  
    // displaying initial parameters 
    cout << "Current parameters are :\n"; 
    cout << "max_load_factor= " << s1.max_load_factor() << endl; 
    cout << "load_factor= " << s1.load_factor() << endl; 
    cout << "size of s1= " << s1.size() << endl; 
    cout << "bucket_count= " << s1.bucket_count() << endl; 
  
    return 0; 
}
输出:
Current parameters are :
max_load_factor= 1
load_factor= 0.571429
size of s1= 4
bucket_count= 7

程序2

// c++ program to illustrate 
// unordered_multiset::max_load_factor() 
#include <iostream> 
#include <unordered_set> 
   
using namespace std; 
   
int main() 
{ 
    // declaration 
    unordered_multiset<char> s1; 
    s1 = { 'a', 'b', 'c', 'd' }; 
   
    // displaying initial parameters 
    cout << "Current parameters are :\n"; 
    cout << "max_load_factor= " << s1.max_load_factor() << endl; 
    cout << "load_factor= " << s1.load_factor() << endl; 
    cout << "size of s1= " << s1.size() << endl; 
    cout << "bucket_count= " << s1.bucket_count() << endl; 
   
    // changing max_load_factor 
    s1.max_load_factor(0.5); 
    cout << endl; 
   
    // displaying final parameters 
    cout << "Final parameters are :\n"; 
    cout << "max_load_factor= " << s1.max_load_factor() << endl; 
    cout << "load_factor= " << s1.load_factor() << endl; 
    cout << "size of s1= " << s1.size() << endl; 
    cout << "bucket_count= " << s1.bucket_count() << endl; 
   
    return 0; 
}
输出:
Current parameters are :
max_load_factor= 1
load_factor= 0.571429
size of s1= 4
bucket_count= 7

Final parameters are :
max_load_factor= 0.5
load_factor= 0.235294
size of s1= 4
bucket_count= 17



注:本文由纯净天空筛选整理自Kushagra7744大神的英文原创作品 unordered_multiset max_load_factor() in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。