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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。