unordered_set::max_load_factor()是C++ STL中的一個函數,該函數返回(或設置)無序設置容器的當前最大負載係數。
負載係數是容器中的元素數與鏟鬥數(bucket_count)之比。默認情況下,無序設置容器的最大負載係數設置為1.0。
max_load_factor()
用法:
unordered_set_name.max_load_factor()
返回值此方法返回當前的最大負載係數。
以下示例程序旨在說明unordered_set::max_load_factor()方法:
// C++ program o illustrate the 
// unordered_set::max_load_factor() function 
  
#include <iostream> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
    unordered_set<int> uset = { 1, 5, 4, 7 }; 
  
    // Get the max_load_factor of uset 
    cout << "Maximum load factor of uset: "
         << uset.max_load_factor() 
         << endl; 
  
    // Now check the current load factor 
    cout << "Current load factor of uset: "
         << uset.load_factor(); 
}
輸出:
Maximum load factor of uset: 1 Current load factor of uset: 0.8
max_load_factor(浮點)
用法
unordered_set_name.max_load_factor(float z)
參數:該方法將浮點數作為要設置max_load_factor的參數。
返回值:此方法不返回任何值。
以下示例程序旨在說明unordered_set::max_load_factor(float)方法:
// C++ program to illustrate the 
// unordered_set::max_load_factor() function 
  
#include <iostream> 
#include <unordered_set> 
using namespace std; 
  
int main() 
{ 
    unordered_set<int> uset = { 1, 5, 4, 7 }; 
  
    // Now set the max_load_factor as  0.5 
    uset.max_load_factor(0.5); 
  
    // Now get the new max_load_factor of uset 
    cout << "New Maximum load factor of uset: "
         << uset.max_load_factor() 
         << endl; 
  
    // Check the new load factor 
    cout << "Current load factor of uset1: "
         << uset.load_factor() 
         << endl; 
}
輸出:
New Maximum load factor of uset: 0.5 Current load factor of uset1: 0.363636
注:本文由純淨天空篩選整理自tufan_gupta2000大神的英文原創作品 unordered_set max_load_factor() in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
