Files
hello-algo/en/codes/cpp/chapter_hashing/built_in_hash.cpp
Yudong Jin 14c314c08c Retranslate the complete English edition from Simplified Chinese (#2010)
* Retranslate the complete English edition from Simplified Chinese

* Polish three English explanations after reader-focused review
2026-10-31 03:35:51 +08:00

30 lines
911 B
C++

/**
* File: built_in_hash.cpp
* Created Time: 2023-06-21
* Author: krahets (krahets@163.com)
*/
#include "../utils/common.hpp"
/* Driver code */
int main() {
int num = 3;
size_t hashNum = hash<int>()(num);
cout << "Integer " << num << " has hash value " << hashNum << "\n";
bool bol = true;
size_t hashBol = hash<bool>()(bol);
cout << "Boolean " << bol << " has hash value " << hashBol << "\n";
double dec = 3.14159;
size_t hashDec = hash<double>()(dec);
cout << "Floating-point number " << dec << " has hash value " << hashDec << "\n";
string str = "Hello 算法";
size_t hashStr = hash<string>()(str);
cout << "String " << str << " has hash value " << hashStr << "\n";
// C++ std::hash provides hashing for fundamental types and selected standard-library types
// For arrays and unsupported object types, supply your own hash implementation
}