//
// Created by light on 19-11-4.
//
#include
#include
#include
using namespace std;
class Customer {
};
// å½¢å¼ä¸ éè¿ä¸ä¸ªç±»ï¼éè½½äºæä½ç¬¦()çæ¹å¼ï¼å½¢æäºä¸ä¸ªä»¿å½æ°ï¼å½æ°å¯¹è±¡ï¼
class CustomerHash {
public:
size_t operator()(const Customer &c) const {
// return ...;
}
};
// å½¢å¼äº è¿ä¸ªæ¹æ³å®é
æ¯éè¿æå®äºä¸ä¸ªå½æ°æéçæ¹å¼æ¥éç¥å®¹å¨ï¼å¯¹äºè¿ä¸ªèªå®ä¹ç±»å°åºåºè¯¥ä½¿ç¨åªä¸ªhash function
size_t customer_hash_func(const Customer &t) {
// return ...;
}
// å½¢å¼ä¸ 以struct hash åç¹åå½¢å¼å®ç°hash function
namespace std { // å¿
é¡»æ¾å¨stdéé¢
template<>
struct hash : public __hash_base { // ç»§æ¿ä¸ç»§æ¿é½å¯ä»¥!
size_t
operator()(const Customer&s) const noexcept {
// return ...;
}
};
}
// ä¸è½çHashFunction 使ç¨variadic templates
// (4)
template
inline void hash_combine(size_t& seed, const T& val){
seed = std::hash()(val) + 0x9e3779b9
+ (seed << 6) + (seed >> 2);
}
// (3)
template
inline void hash_val(size_t& seed, const T& val){
hash_combine(seed, val);
}
// (2)
template
inline void hash_val(size_t& seed, const T& val, const Types&... args){
hash_combine(seed, val);
hash_val(seed, args...);
}
// (1)
template
inline size_t hash_val(const Types&... args){
size_t seed = 0;
hash_val(seed, args...);
return seed;
}
int main() {
unordered_set unorderedSet;
unordered_setcustset(20,customer_hash_func);
unordered_set unset;
int *p= reinterpret_cast(new Customer());
cout<