30 #ifndef _FUNCTIONAL_HASH_H 31 #define _FUNCTIONAL_HASH_H 1 33 #pragma GCC system_header 37 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Result,
typename _Arg>
52 typedef _Result result_type;
53 typedef _Arg argument_type;
57 template<
typename _Tp>
60 template<
typename _Tp,
typename =
void>
65 __poison_hash(__poison_hash&&);
69 template<
typename _Tp>
70 struct __poison_hash<_Tp, __void_t<decltype(hash<_Tp>()(declval<_Tp>()))>>
75 template<typename _Tp, bool = is_enum<_Tp>::value>
80 __hash_enum(__hash_enum&&);
85 template<
typename _Tp>
86 struct __hash_enum<_Tp, true> :
public __hash_base<size_t, _Tp>
89 operator()(_Tp __val)
const noexcept
91 using __type =
typename underlying_type<_Tp>::type;
92 return hash<__type>{}(
static_cast<__type
>(__val));
98 template<
typename _Tp>
99 struct hash : __hash_enum<_Tp>
103 template<
typename _Tp>
104 struct hash<_Tp*> :
public __hash_base<size_t, _Tp*>
107 operator()(_Tp* __p)
const noexcept
108 {
return reinterpret_cast<size_t>(__p); }
112 #define _Cxx_hashtable_define_trivial_hash(_Tp) \ 114 struct hash<_Tp> : public __hash_base<size_t, _Tp> \ 117 operator()(_Tp __val) const noexcept \ 118 { return static_cast<size_t>(__val); } \ 122 _Cxx_hashtable_define_trivial_hash(
bool)
125 _Cxx_hashtable_define_trivial_hash(
char)
128 _Cxx_hashtable_define_trivial_hash(
signed char)
131 _Cxx_hashtable_define_trivial_hash(
unsigned char)
134 _Cxx_hashtable_define_trivial_hash(
wchar_t)
137 _Cxx_hashtable_define_trivial_hash(char16_t)
140 _Cxx_hashtable_define_trivial_hash(char32_t)
143 _Cxx_hashtable_define_trivial_hash(
short)
146 _Cxx_hashtable_define_trivial_hash(
int)
149 _Cxx_hashtable_define_trivial_hash(
long)
152 _Cxx_hashtable_define_trivial_hash(
long long)
155 _Cxx_hashtable_define_trivial_hash(
unsigned short)
158 _Cxx_hashtable_define_trivial_hash(
unsigned int)
161 _Cxx_hashtable_define_trivial_hash(
unsigned long)
164 _Cxx_hashtable_define_trivial_hash(
unsigned long long)
166 #ifdef __GLIBCXX_TYPE_INT_N_0 167 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_0)
168 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_0
unsigned)
170 #ifdef __GLIBCXX_TYPE_INT_N_1 171 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_1)
172 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_1
unsigned)
174 #ifdef __GLIBCXX_TYPE_INT_N_2 175 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_2)
176 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_2
unsigned)
178 #ifdef __GLIBCXX_TYPE_INT_N_3 179 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_3)
180 _Cxx_hashtable_define_trivial_hash(__GLIBCXX_TYPE_INT_N_3
unsigned)
183 #undef _Cxx_hashtable_define_trivial_hash 188 hash(
const void* __ptr,
size_t __clength,
189 size_t __seed = static_cast<size_t>(0xc70f6907UL))
190 {
return _Hash_bytes(__ptr, __clength, __seed); }
192 template<
typename _Tp>
194 hash(
const _Tp& __val)
195 {
return hash(&__val,
sizeof(__val)); }
197 template<
typename _Tp>
199 __hash_combine(
const _Tp& __val,
size_t __hash)
200 {
return hash(&__val,
sizeof(__val), __hash); }
204 struct _Fnv_hash_impl
207 hash(
const void* __ptr,
size_t __clength,
208 size_t __seed = static_cast<size_t>(2166136261UL))
209 {
return _Fnv_hash_bytes(__ptr, __clength, __seed); }
211 template<
typename _Tp>
213 hash(
const _Tp& __val)
214 {
return hash(&__val,
sizeof(__val)); }
216 template<
typename _Tp>
218 __hash_combine(
const _Tp& __val,
size_t __hash)
219 {
return hash(&__val,
sizeof(__val), __hash); }
224 struct hash<float> :
public __hash_base<size_t, float>
227 operator()(
float __val)
const noexcept
230 return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0;
236 struct hash<double> :
public __hash_base<size_t, double>
239 operator()(
double __val)
const noexcept
242 return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0;
249 :
public __hash_base<size_t, long double>
252 operator()(
long double __val)
const noexcept;
261 template<
typename _Hash>
269 _GLIBCXX_END_NAMESPACE_VERSION
272 #endif // _FUNCTIONAL_HASH_H
ISO C++ entities toplevel namespace is std.
Primary class template hash.