c++ - Why std::hash<int> seems to be identity function -


#include <iostream>  int main() {     std::hash<int> hash_f;     std::cout << hash_f(0) << std::endl;     std::cout << hash_f(1) << std::endl;     std::cout << hash_f(2) << std::endl;     std::cout << hash_f(3) << std::endl; } 

i compile "g++ main.cpp -std=c++11" , result :

0 1 2 3 

why happening? don't use library , don't have specialized hashing function.

addendum : wanted define hash unordered_set of unordered_set of int hash of set being sum of components hashs, if it's identity it's not cool because hash of {2,4} same hash of {1,5}. simplest way avoid may use std::hash double function.

it seems identity, allowed distinct.. cpp reference

the actual hash functions implementation-dependent , not required fulfill other quality criteria except specified above. notably, implementations use trivial (identity) hash functions map integer itself. in other words, these hash functions designed work unordered associative containers, not cryptographic hashes, example. ....


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -