需要自定义hash的unordered_set和unordered_map
#include <iostream>
#include <bits/stdc++.h>//万能头文件
//存储结构
struct Record{
int val1;
int val2;
Record(int a, int b){
val1 = a;
val2 = b;
}
};
//转换成hash
struct RecordHash{
size_t operator()(const Record& rhs) const{
return hash<int>()(rhs.val1)^hash<int>()(rhs.val2);
}
};
//比较
struct RecordCompare{
bool operator()(const Record& l, const Record& r) const{
return l.val1==r.val1&&l.val2==r.val2;
}
}
//定义unordered_set
unordered_set(Record,RecordHash,RecordCompare) S;
S.insert(Record(1,2));
S.find(Record(1,2));
//定义unordered_map
unordered_map<Rrecord,int,RecordHash,RecordCompare> S;
S.insert(Record(1,2),1);