📌  相关文章
📜  C++ STL中的unordered_multiset max_load_factor()

📅  最后修改于: 2021-05-30 19:53:06             🧑  作者: Mango

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 
#include 
  
using namespace std;
  
int main()
{
    // declaration
    unordered_multiset 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 
#include 
   
using namespace std;
   
int main()
{
    // declaration
    unordered_multiset 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
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”