16 #ifndef INCLUDE_NN_NLIB_HASH_H_ 17 #define INCLUDE_NN_NLIB_HASH_H_ 22 #if defined(__cpp_alias_templates) 25 using Hash = std::hash<T>;
27 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) namespace std { 28 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) namespace std { 29 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) namespace std { 30 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) } 31 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) } 32 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) } 33 #define NLIB_DEFINE_STD_HASH_T(tp) \ 36 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 38 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 39 template<class targ1, class targ2> \ 40 struct hash<tp<targ1, targ2> > { \ 41 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { \ 42 return val.GetHash(); \ 50 inline size_t Times33(
const unsigned char* p,
size_t n)
NLIB_NOEXCEPT {
52 for (; n != 0; --n, ++p) {
53 hash = hash * 33 + *p;
60 struct SimpleHash :
public std::unary_function<T, size_t> {
62 return detail::Times33(reinterpret_cast<const unsigned char*>(&val),
sizeof(val));
67 struct Hash :
public SimpleHash<T> {};
70 struct Hash<bool> :
public SimpleHash<bool> {};
72 struct Hash<char> :
public SimpleHash<char> {};
74 struct Hash<signed char> :
public SimpleHash<signed char> {};
76 struct Hash<unsigned char> :
public SimpleHash<unsigned char> {};
78 struct Hash<wchar_t> :
public SimpleHash<wchar_t> {};
80 struct Hash<short> :
public SimpleHash<short> {};
82 struct Hash<unsigned short> :
public SimpleHash<unsigned short> {};
84 struct Hash<int> :
public SimpleHash<int> {};
86 struct Hash<unsigned int> :
public SimpleHash<unsigned int> {};
88 struct Hash<long> :
public SimpleHash<long> {};
90 struct Hash<unsigned long> :
public SimpleHash<unsigned long> {};
92 struct Hash<long long> :
public SimpleHash<long long> {};
94 struct Hash<unsigned long long> :
public SimpleHash<unsigned long long> {};
96 struct Hash<float> :
public SimpleHash<float> {};
98 struct Hash<double> :
public SimpleHash<double> {};
100 struct Hash<T*> :
public SimpleHash<T*> {};
105 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) NLIB_NAMESPACE_BEGIN 106 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) NLIB_NAMESPACE_BEGIN namespace ns3 { 107 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) \ 108 NLIB_NAMESPACE_BEGIN namespace ns3 { \ 110 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) NLIB_NAMESPACE_END 111 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) \ 114 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) \ 119 #define NLIB_DEFINE_STD_HASH_T(tp) \ 122 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 124 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 125 template<class targ1, class targ2> \ 126 struct Hash<tp<targ1, targ2> > { \ 127 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { \ 128 return val.GetHash(); \ 135 #endif // INCLUDE_NN_NLIB_HASH_H_ #define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A file that contains the configuration information for each development environment.