Created
May 29, 2016 13:22
-
-
Save amorphobia/637e07b0d325c1396db17d741d7bd959 to your computer and use it in GitHub Desktop.
Copied from hash_range in Boost.
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
#ifndef HASH_EXTENDED_H | |
#define HASH_EXTENDED_H | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <algorithm> | |
namespace std { | |
template<typename T> struct hash<vector<T>> { | |
inline size_t operator() (const vector<T>& vec) const { | |
hash<T> hasher; | |
size_t seed = 0; | |
for (auto& i : vec) { | |
seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
} | |
return seed; | |
} | |
}; | |
template<typename T> struct hash<unordered_multiset<T>> { | |
inline size_t operator() (const unordered_multiset<T>& uset) const { | |
hash<T> hasher; | |
vector<size_t> hashes; | |
for (auto& i : uset) { | |
hashes.push_back(hasher(i)); | |
} | |
sort(hashes.begin(), hashes.end()); | |
hash<vector<size_t>> h; | |
return h(hashes); | |
} | |
}; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment