Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _FUNCTIONAL_HASH_H
00031 #define _FUNCTIONAL_HASH_H 1
00032
00033 #pragma GCC system_header
00034
00035 #include <bits/hash_bytes.h>
00036
00037 namespace std _GLIBCXX_VISIBILITY(default)
00038 {
00039 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 template<typename _Result, typename _Arg>
00050 struct __hash_base
00051 {
00052 typedef _Result result_type;
00053 typedef _Arg argument_type;
00054 };
00055
00056
00057 template<typename _Tp>
00058 struct hash : public __hash_base<size_t, _Tp>
00059 {
00060 size_t
00061 operator()(_Tp __val) const;
00062 };
00063
00064
00065 template<typename _Tp>
00066 struct hash<_Tp*> : public __hash_base<size_t, _Tp*>
00067 {
00068 size_t
00069 operator()(_Tp* __p) const
00070 { return reinterpret_cast<size_t>(__p); }
00071 };
00072
00073
00074 #define _Cxx_hashtable_define_trivial_hash(_Tp) \
00075 template<> \
00076 inline size_t \
00077 hash<_Tp>::operator()(_Tp __val) const \
00078 { return static_cast<size_t>(__val); }
00079
00080
00081 _Cxx_hashtable_define_trivial_hash(bool);
00082
00083
00084 _Cxx_hashtable_define_trivial_hash(char);
00085
00086
00087 _Cxx_hashtable_define_trivial_hash(signed char);
00088
00089
00090 _Cxx_hashtable_define_trivial_hash(unsigned char);
00091
00092
00093 _Cxx_hashtable_define_trivial_hash(wchar_t);
00094
00095
00096 _Cxx_hashtable_define_trivial_hash(char16_t);
00097
00098
00099 _Cxx_hashtable_define_trivial_hash(char32_t);
00100
00101
00102 _Cxx_hashtable_define_trivial_hash(short);
00103
00104
00105 _Cxx_hashtable_define_trivial_hash(int);
00106
00107
00108 _Cxx_hashtable_define_trivial_hash(long);
00109
00110
00111 _Cxx_hashtable_define_trivial_hash(long long);
00112
00113
00114 _Cxx_hashtable_define_trivial_hash(unsigned short);
00115
00116
00117 _Cxx_hashtable_define_trivial_hash(unsigned int);
00118
00119
00120 _Cxx_hashtable_define_trivial_hash(unsigned long);
00121
00122
00123 _Cxx_hashtable_define_trivial_hash(unsigned long long);
00124
00125 #undef _Cxx_hashtable_define_trivial_hash
00126
00127 struct _Hash_impl
00128 {
00129 static size_t
00130 hash(const void* __ptr, size_t __clength,
00131 size_t __seed = static_cast<size_t>(0xc70f6907UL))
00132 { return _Hash_bytes(__ptr, __clength, __seed); }
00133
00134 template<typename _Tp>
00135 static size_t
00136 hash(const _Tp& __val)
00137 { return hash(&__val, sizeof(__val)); }
00138
00139 template<typename _Tp>
00140 static size_t
00141 __hash_combine(const _Tp& __val, size_t __hash)
00142 { return hash(&__val, sizeof(__val), __hash); }
00143 };
00144
00145 struct _Fnv_hash_impl
00146 {
00147 static size_t
00148 hash(const void* __ptr, size_t __clength,
00149 size_t __seed = static_cast<size_t>(2166136261UL))
00150 { return _Fnv_hash_bytes(__ptr, __clength, __seed); }
00151
00152 template<typename _Tp>
00153 static size_t
00154 hash(const _Tp& __val)
00155 { return hash(&__val, sizeof(__val)); }
00156
00157 template<typename _Tp>
00158 static size_t
00159 __hash_combine(const _Tp& __val, size_t __hash)
00160 { return hash(&__val, sizeof(__val), __hash); }
00161 };
00162
00163
00164 template<>
00165 inline size_t
00166 hash<float>::operator()(float __val) const
00167 {
00168
00169 return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0;
00170 }
00171
00172
00173 template<>
00174 inline size_t
00175 hash<double>::operator()(double __val) const
00176 {
00177
00178 return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0;
00179 }
00180
00181
00182 template<>
00183 _GLIBCXX_PURE size_t
00184 hash<long double>::operator()(long double __val) const;
00185
00186
00187
00188 _GLIBCXX_END_NAMESPACE_VERSION
00189 }
00190
00191 #endif // _FUNCTIONAL_HASH_H