Brichkandy
Brichkandy

Reputation: 11

Generating a hash key using cpp

I was trying to generate hash keys for unsigned long long variables in cpp using the following code:

#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;
}

But I ended up getting the same values I provided as inputs in the form of signature. Please let me know if I did any mistake. Here's the link I referred to to do this. hashing function in cpp

Upvotes: 1

Views: 1918

Answers (1)

pstanisz
pstanisz

Reputation: 181

According to std::hash description at 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.

Upvotes: 1

Related Questions