Last active
January 14, 2017 11:00
-
-
Save fpopic/924e752f6db720081b7cde8c2e3a7d5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // to enable O(1) lookup for unordered containers | |
| // XOR (^) and SHIFT (<<,>>) operations will make (5,3) != (3,5) | |
| namespace std { | |
| template<typename T, typename U> | |
| class hash<pair<T, U>> { | |
| public : | |
| size_t operator()(const pair<T, U>& p) const { | |
| size_t seed = 0; | |
| seed ^= p.first + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
| seed ^= p.second + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
| return seed; | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment