自定义PIIhash和使用例子
作者:
夜林
,
2022-04-24 23:17:32
,
所有人可见
,
阅读 193
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <chrono>
using namespace std;
typedef pair<int, int> PII;
struct custom_hash {
static int splitmix64(int x) {
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return x;
}
size_t operator () (PII x) const {
static const int FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
return splitmix64(x.first + x.second + FIXED_RANDOM);
}
};
unordered_map<PII,int, custom_hash>L,R;
int main()
{
L[{1,2}] = 3;
L[{1,3}] = 3;
unordered_map<PII,int, custom_hash>:: iterator i;
for(i=L.begin(); i != L.end(); i++){
cout << (*i).second << endl;
}
return 0;
}