Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Circle {
- double x;
- double y;
- double r;
- };
- struct Dumbbell {
- Circle circle1;
- Circle circle2;
- string text;
- };
- struct DumbbellHash {
- size_t operator() (const Dumbbell& dumbbell) const {
- auto h_x = d_hasher_(dumbbell.circle1.x);
- auto h_y = d_hasher_(dumbbell.circle1.y);
- auto h_r = d_hasher_(dumbbell.circle1.r);
- auto circle1_hash = h_x + h_y * 37 + h_r * (37 * 37);
- auto h_x2 = d_hasher_(dumbbell.circle2.x);
- auto h_y2 = d_hasher_(dumbbell.circle2.y);
- auto h_r2 = d_hasher_(dumbbell.circle2.r);
- auto circle2_hash = h_x2 + h_y2 * 37 + h_r2 * (37 * 37);
- return (circle1_hash * (37 * 37 * 37) + circle2_hash + s_hasher_(dumbbell.text));
- }
- private:
- std::hash<double> d_hasher_;
- hash<string> s_hasher_;
- };
- int main() {
- DumbbellHash hash;
- Dumbbell dumbbell{{10, 11.5, 2.3}, {3.14, 15, -8}, "abc"s};
- cout << "Dumbbell hash "s << hash(dumbbell);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement