我尝试使用以下代码在 cpp 中为 unsigned long long 变量生成散列键:
#include <iostream>
#include <functional>
#include <string>
#include <bitset>
#include <stdlib.h>
int main()
{
using namespace std;
unsigned long long pc[100];
unsigned long long h[100];
for(int i=0;i<100;i++)
{
pc[i] = i%50;
hash<unsigned long long> hash_fn;
h[i] = hash_fn(pc[i]);
std::cout <<pc[i]<< "=" << h[i] << '\n';
}
return 0;
}
但我最终得到的值与我以签名形式作为输入提供的值相同。如果我做错了,请告诉我。 这是我提到的执行此操作的链接。 hashing function in cpp
最佳答案
根据 std::hash 描述 cppreference :
Notably, some implementations use trivial (identity) hash functions which map an integer to itself. In other words, these hash functions are designed to work with unordered associative containers, but not as cryptographic hashes, for example.
关于c++ - 使用 cpp 生成哈希键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29624375/