unordered_multiset::hash_function()是C++ STL中的内置函数,用于获取哈希函数。该哈希函数是一元函数,仅接受单个参数,并基于该参数返回一个唯一的大小为size_t的值。
用法:
unordered_multiset_name.hash_function()
参数:该函数不接受任何参数。
返回值:该函数返回哈希函数。
以下示例程序旨在说明unordered_multiset::hash_function()函数:
程序1:
// CPP program to illustrate the 
// unordered_multiset::hash_function() function 
  
#include <iostream> 
#include <string> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
  
    unordered_multiset<string> sampleSet = { "geeks1", "geeks1", "for", "geeks2" }; 
  
    // use of hash_function 
    unordered_multiset<string>::hasher fn = sampleSet.hash_function(); 
  
    cout << fn("geeks") << endl; 
  
    for (auto it = sampleSet.begin(); it != sampleSet.end(); it++) { 
        cout << *it << " "; 
    } 
    cout << endl; 
  
    return 0; 
}
输出:
15276750567035005396 geeks2 for geeks1 geeks1
程序2:
// CPP program to illustrate the 
// unordered_multiset::hash_function () function 
  
#include <iostream> 
#include <string> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
  
    unordered_multiset<string> sampleSet; 
  
    // use of hash_function 
    unordered_multiset<string>::hasher fn = sampleSet.hash_function(); 
  
    cout << fn("geeksforgeeks") << endl; 
  
    return 0; 
}
输出:
5146686323530302118
相关用法
- C++ log()用法及代码示例
- C++ div()用法及代码示例
- C++ fma()用法及代码示例
- C++ real()用法及代码示例
- C++ map key_comp()用法及代码示例
- C++ imag()用法及代码示例
- C++ regex_iterator()用法及代码示例
- C++ valarray tan()用法及代码示例
- C++ valarray pow()用法及代码示例
- C++ valarray sin()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 unordered_multiset hash_function() function in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
