unordered_set key_eq()是C++ STL中的内置函数,根据比较结果返回布尔值。它返回unordered_set使用的键等效项比较谓词。键等价比较是一个谓词,该谓词接受两个参数并返回一个bool值,指示它们是否相等。
句法:
key_equal key_eq() const
返回值:该方法返回键相等性比较对象。
时间复杂度: O(1)
范例1:
#include
#include
#include
using namespace std;
int main()
{
// unordered_set ms is created
unordered_set ms;
bool res = ms.key_eq()("a", "A");
cout << "ms.key_eq() is ";
if (res == 1) {
cout << "case insensitive";
}
else {
// res is 0 as arguments are not equivalent
cout << "case sensitive";
}
cout << "\n";
return 0;
}
输出:
ms.key_eq() is case sensitive
范例2:
#include
#include
#include
using namespace std;
int main()
{
// unordered_set mp is created
unordered_set mp;
// the 2 strings are compared
bool
r
= mp.key_eq()(
"1000 is a huge number",
"2000 is a huge number");
cout << "strings are ";
if (r == 1) {
cout << "same";
}
else {
// the strings are not same so r=0
cout << "not same";
}
cout << "\n";
return 0;
}
输出:
strings are not same
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。