mirror of
https://github.com/krahets/hello-algo.git
synced 2026-12-01 19:31:00 +08:00
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]>
30 lines
939 B
C++
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
|
|
}
|