About gcc and std::hash

Revision en5, by komendart, 2016-05-18 19:54:02

Hi everyone!

I don't know, maybe this topis was discussed on Codeforces but google didn't help me.

It seems that standart hash function in gcc works badly (for Visual C++ all is good).

For 0 ≤ x ≤ 232 - 1

std::hash<int>()(x) == x 
std::hash<long long>()(x) == x

For any other number

std::hash<long long>()(x + (1LL << 32)) == std::hash<long long>()(x)

For example code in spoiler works more than 10 seconds on Codeforces because hashes of all numbers are equal to zero.

Code

What can we do without writing our own hash function?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English komendart 2016-05-18 19:54:02 32 Tiny change: ' '
ru3 Russian komendart 2016-05-18 19:53:24 32 Мелкая правка: '< 32)) == x\n~~~~~\n\' -> '< 32)) == std::hash<long long>()(x)\n~~~~~\n\'
en4 English komendart 2016-05-18 19:43:41 15 Tiny change: 're than 10s on Codef' -
en3 English komendart 2016-05-18 19:31:42 15 Tiny change: ' summary="Код">\n\n~~~~' -> ' summary="Code">\n\n~~~~'
en2 English komendart 2016-05-18 19:28:39 11 Tiny change: 't google don't help m' -> 't google didn't help m'
en1 English komendart 2016-05-18 19:28:09 923 Initial revision for English translation
ru2 Russian komendart 2016-05-18 19:18:56 77
ru1 Russian komendart 2016-05-18 19:17:19 885 Первая редакция (опубликовано)