Skip to content

Commit 276ab0b

Browse files
Chilleesimonlindholm
authored andcommitted
Updated policy hashmap with custom hash (#89)
1 parent 3827074 commit 276ab0b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

content/data-structures/HashMap.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Author: Simon Lindholm
2+
* Author: Simon Lindholm, chilli
33
* Date: 2018-07-23
44
* License: CC0
55
* Source: http://codeforces.com/blog/entry/60737
@@ -9,12 +9,19 @@
99
#pragma once
1010

1111
#include <bits/extc++.h> /** keep-include */
12-
__gnu_pbds::gp_hash_table<ll, int> h({},{},{},{}, {1 << 16});
12+
// To use most bits rather than just the lowest ones:
13+
struct chash {
14+
const uint64_t C = ll(2e18 * M_PI) + 71; // large odd number
15+
ll operator()(ll x) const { return __builtin_bswap64(x*C); }
16+
};
17+
__gnu_pbds::gp_hash_table<ll,int,chash> h({},{},{},{},{1<<16});
1318

1419
/** For CodeForces, or other places where hacking might be a problem:
20+
1521
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
16-
struct chash {
17-
int operator()(ll x) const { return x ^ RANDOM; }
22+
struct chash { // To use most bits rather than just the lowest ones:
23+
const uint64_t C = ll(2e18 * M_PI) + 71; // large odd number
24+
ll operator()(ll x) const { return __builtin_bswap64((x^RANDOM)*C); }
1825
};
1926
__gnu_pbds::gp_hash_table<ll, int, chash> h({},{},{},{}, {1 << 16});
2027
*/

0 commit comments

Comments
 (0)