Files
hello-algo/en/codes/cpp/chapter_hashing/built_in_hash.cpp
T
Yudong JinandClaude Opus 5.5 6d19673be3 Fix demo comments and labels that contradict the code (#2048)
Fix Chinese wording that contradicted the demo code: the C++ std::hash
scope, the Rust node-value hash label, the Go Pop comment and the Go
stack test comment. Russian sources and all six editions' snippets
follow; the Go heap snippets drop the repository-only PrintHeap call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 21:50:05 +08:00

30 lines
939 B
C++

/**
* File: built_in_hash.cpp
* Created Time: 2023-06-21
* Author: krahets ([email protected])
*/
#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";
// In C++, the built-in std::hash() only computes hash values for basic data types and some standard library types (such as std::string)
// Hashing arrays and objects requires a custom implementation
}