unordered_map 的火车头
作者:互联网
#include <functional> template <typename T> inline void hash_combine(std::size_t &seed, const T &val) { seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template <typename T> inline void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); } template <typename T, typename... Types> inline void hash_val(std::size_t &seed, const T &val, const Types &... args) { hash_combine(seed, val); hash_val(seed, args...); } template <typename... Types> inline std::size_t hash_val(const Types &... args) { std::size_t seed = 0; hash_val(seed, args...); return seed; } struct pair_hash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2> &p) const { return hash_val(p.first, p.second); } }; #include <bits/stdc++.h> using namespace std; using ll = long long; int main() { unordered_map<pair<ll, ll>, ll, pair_hash> slopeCount; unordered_set<pair<ll, ll>, pair_hash> seen; return 0; }
标签:std,map,火车头,hash,val,seed,const,unordered,size 来源: https://www.cnblogs.com/LH2000/p/14407030.html