cpp ユーティリティで std::hash を使用して、文字列のハッシュを生成しています。私の要件は、11 桁の固定サイズのハッシュを生成することです。衝突が起こらないようにするために、ハッシュ関数は優れている必要はありません。私が持っている唯一の要件は、11 桁の固定サイズのハッシュを生成することです。どのような入力でも構いません。カスタム ハッシュ関数を使用することもできます。
#include <iostream>
#include <string>
#include <functional>
#include <iomanip>
#include <unordered_set>
int main()
{
std::hash<std::string> hash_fn;
std::string s1 = "Stand back! I've got jimmies!";
size_t hash1 = hash_fn(s1);
std::cout << hash1 << '\n'; // OUTPUT: 3544599705012401047
s1 = "h";
hash1 = hash_fn(s1);
std::cout << hash1 << '\n'; // OUTPUT: 11539147918811572172
return 1;
}