Created
December 22, 2016 03:06
-
-
Save reddragon/e6363719eba507cedd10a475915b8317 to your computer and use it in GitHub Desktop.
Hash Function for unordered_map
This file contains 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
struct Slope { | |
int n, d; | |
Slope(int nn, int dd) { | |
int g = gcd(abs(nn), abs(dd)); | |
// cout << "gcd of " << nn << ", " << dd << " is: " << g << endl; | |
n = (g > 0 ? nn/g : nn); | |
d = (g > 0 ? dd/g : dd); | |
} | |
}; | |
struct Cmp { | |
size_t operator()(const Slope& k) const { | |
return (k.n<<3)^k.d; | |
} | |
size_t operator()(const Slope& k1, const Slope& k2) const { | |
return k1.n == k2.n && k1.d == k2.d; | |
} | |
}; | |
vector<unordered_map<Slope, vector<int>, Cmp, Cmp>> v; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment