| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#ifndef _GLIBCXX_TR1_FUNCTIONAL_HASH_H |
| 31 |
#define _GLIBCXX_TR1_FUNCTIONAL_HASH_H 1 |
| 32 |
|
| 33 |
#ifdef _GLIBCXX_SYSHDR |
| 34 |
#pragma GCC system_header |
| 35 |
#endif |
| 36 |
|
| 37 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 38 |
{ |
| 39 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 40 |
|
| 41 |
namespace tr1 |
| 42 |
{ |
| 43 |
|
| 44 |
#pragma GCC diagnostic push |
| 45 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
template<typename _Tp> |
| 51 |
struct hash : public std::unary_function<_Tp, size_t> |
| 52 |
{ |
| 53 |
size_t |
| 54 |
operator()(_Tp __val) const; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
template<typename _Tp> |
| 59 |
struct hash<_Tp*> : public std::unary_function<_Tp*, size_t> |
| 60 |
{ |
| 61 |
size_t |
| 62 |
operator()(_Tp* __p) const |
| 63 |
{ return reinterpret_cast<size_t>(__p); } |
| 64 |
}; |
| 65 |
#pragma GCC diagnostic pop |
| 66 |
|
| 67 |
|
| 68 |
#define _TR1_hashtable_define_trivial_hash(_Tp) \ |
| 69 |
template<> \ |
| 70 |
inline size_t \ |
| 71 |
hash<_Tp>::operator()(_Tp __val) const \ |
| 72 |
{ return static_cast<size_t>(__val); } |
| 73 |
|
| 74 |
#pragma GCC diagnostic push |
| 75 |
#pragma GCC diagnostic ignored "-Wlong-long" |
| 76 |
_TR1_hashtable_define_trivial_hash(bool) |
| 77 |
_TR1_hashtable_define_trivial_hash(char) |
| 78 |
_TR1_hashtable_define_trivial_hash(signed char) |
| 79 |
_TR1_hashtable_define_trivial_hash(unsigned char) |
| 80 |
_TR1_hashtable_define_trivial_hash(wchar_t) |
| 81 |
_TR1_hashtable_define_trivial_hash(short) |
| 82 |
_TR1_hashtable_define_trivial_hash(int) |
| 83 |
_TR1_hashtable_define_trivial_hash(long) |
| 84 |
_TR1_hashtable_define_trivial_hash(long long) |
| 85 |
_TR1_hashtable_define_trivial_hash(unsigned short) |
| 86 |
_TR1_hashtable_define_trivial_hash(unsigned int) |
| 87 |
_TR1_hashtable_define_trivial_hash(unsigned long) |
| 88 |
_TR1_hashtable_define_trivial_hash(unsigned long long) |
| 89 |
#pragma GCC diagnostic pop |
| 90 |
|
| 91 |
#undef _TR1_hashtable_define_trivial_hash |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
template<size_t> |
| 102 |
struct _Fnv_hash_base |
| 103 |
{ |
| 104 |
template<typename _Tp> |
| 105 |
static size_t |
| 106 |
hash(const _Tp* __ptr, size_t __clength) |
| 107 |
{ |
| 108 |
size_t __result = 0; |
| 109 |
const char* __cptr = reinterpret_cast<const char*>(__ptr); |
| 110 |
for (; __clength; --__clength) |
| 111 |
__result = (__result * 131) + *__cptr++; |
| 112 |
return __result; |
| 113 |
} |
| 114 |
}; |
| 115 |
|
| 116 |
template<> |
| 117 |
struct _Fnv_hash_base<4> |
| 118 |
{ |
| 119 |
template<typename _Tp> |
| 120 |
static size_t |
| 121 |
hash(const _Tp* __ptr, size_t __clength) |
| 122 |
{ |
| 123 |
size_t __result = static_cast<size_t>(2166136261UL); |
| 124 |
const char* __cptr = reinterpret_cast<const char*>(__ptr); |
| 125 |
for (; __clength; --__clength) |
| 126 |
{ |
| 127 |
__result ^= static_cast<size_t>(*__cptr++); |
| 128 |
__result *= static_cast<size_t>(16777619UL); |
| 129 |
} |
| 130 |
return __result; |
| 131 |
} |
| 132 |
}; |
| 133 |
|
| 134 |
template<> |
| 135 |
struct _Fnv_hash_base<8> |
| 136 |
{ |
| 137 |
template<typename _Tp> |
| 138 |
static size_t |
| 139 |
hash(const _Tp* __ptr, size_t __clength) |
| 140 |
{ |
| 141 |
#pragma GCC diagnostic push |
| 142 |
#pragma GCC diagnostic ignored "-Wlong-long" |
| 143 |
size_t __result |
| 144 |
= static_cast<size_t>(14695981039346656037ULL); |
| 145 |
const char* __cptr = reinterpret_cast<const char*>(__ptr); |
| 146 |
for (; __clength; --__clength) |
| 147 |
{ |
| 148 |
__result ^= static_cast<size_t>(*__cptr++); |
| 149 |
__result *= static_cast<size_t>(1099511628211ULL); |
| 150 |
} |
| 151 |
return __result; |
| 152 |
#pragma GCC diagnostic pop |
| 153 |
} |
| 154 |
}; |
| 155 |
|
| 156 |
struct _Fnv_hash |
| 157 |
: public _Fnv_hash_base<sizeof(size_t)> |
| 158 |
{ |
| 159 |
using _Fnv_hash_base<sizeof(size_t)>::hash; |
| 160 |
|
| 161 |
template<typename _Tp> |
| 162 |
static size_t |
| 163 |
hash(const _Tp& __val) |
| 164 |
{ return hash(&__val, sizeof(__val)); } |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
template<> |
| 169 |
inline size_t |
| 170 |
hash<float>::operator()(float __val) const |
| 171 |
{ |
| 172 |
|
| 173 |
return __val != 0.0f ? std::tr1::_Fnv_hash::hash(__val) : 0; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
template<> |
| 178 |
inline size_t |
| 179 |
hash<double>::operator()(double __val) const |
| 180 |
{ |
| 181 |
|
| 182 |
return __val != 0.0 ? std::tr1::_Fnv_hash::hash(__val) : 0; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
template<> |
| 187 |
_GLIBCXX_PURE size_t |
| 188 |
hash<long double>::operator()(long double __val) const; |
| 189 |
|
| 190 |
|
| 191 |
template<> |
| 192 |
_GLIBCXX_PURE size_t |
| 193 |
hash<string>::operator()(string) const; |
| 194 |
|
| 195 |
template<> |
| 196 |
_GLIBCXX_PURE size_t |
| 197 |
hash<const string&>::operator()(const string&) const; |
| 198 |
|
| 199 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 200 |
template<> |
| 201 |
_GLIBCXX_PURE size_t |
| 202 |
hash<wstring>::operator()(wstring) const; |
| 203 |
|
| 204 |
template<> |
| 205 |
_GLIBCXX_PURE size_t |
| 206 |
hash<const wstring&>::operator()(const wstring&) const; |
| 207 |
#endif |
| 208 |
} |
| 209 |
|
| 210 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 211 |
} |
| 212 |
|
| 213 |
#endif |