c++ - 使用 cpp 生成哈希键

标签 c++ hash

我尝试使用以下代码在 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/

相关文章:

c++ - 括号对齐样式 : Break before closing parenthesis

c++ - std::cin 中没有匹配 'operator>>' >>

java - 如何避免在哈希搜索中进行暴力搜索

javascript - NestJS 哈希密码

java - 在java中使用哈希码比较两个大字符串?

c++ - 手动将整数变量放入字符串中

c++ - 为什么我手动调整的、启用 SSE 的代码这么慢?

c++ - 在 Qt 中执行 %LIKE% 查询

java - 搜索哈希表

perl - 在散列键重复中,将值连接到 perl 脚本中的先前键中