c++hash関数
1388 ワード
std::hash
template struct hash;
Unary function object class that defines the default hash function used by the standard library.
いちじげんかんすう
Member functions
operator()
Returns a hash value for its argument, as a value of type size_t.
template struct hash;
Unary function object class that defines the default hash function used by the standard library.
いちじげんかんすう
Member functions
operator()
Returns a hash value for its argument, as a value of type size_t.
#include
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char nts1[] = "Test";
char nts2[] = "Test";
string str1 (nts1);
string str2 (nts2);
hash ptr_hash;
hash str_hash;
cout< cout< cout< cout< cout << "same hashes:
" << boolalpha;
cout << "nts1 and nts2: " << (ptr_hash(nts1)==ptr_hash(nts2)) << '
';
cout << "str1 and str2: " << (str_hash(str1)==str_hash(str2)) << '
';
return 0;
}
:
hash value of nts1: 2071187971
hash value of nts2: 1344341107
hash value of str1: 805092869
hash value of str2: 805092869
same hashes:
nts1 and nts2: false
str1 and str2: true