STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
functional_hash.h File Reference

Go to the source code of this file.

Macros

#define _TR1_hashtable_define_trivial_hash(_Tp)
 

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {tr1/functional}

Macro Definition Documentation

#define _TR1_hashtable_define_trivial_hash (   _Tp)
Value:
template<> \
inline size_t \
hash<_Tp>::operator()(_Tp __val) const \
{ return static_cast<size_t>(__val); }

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Class template hash.

Partial specializations for pointer types.

Explicit specializations for integer types.

Dummy generic implementation (for sizeof(size_t) != 4, 8).

Explicit specializations for float.

Explicit specializations for double.

Explicit specializations for long double.

Explicit specialization of member operator for non-builtin types.

36 {
37 namespace tr1
38 {
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 
42  // Declaration of default hash functor std::tr1::hash. The types for
43  // which std::tr1::hash<T> is well-defined is in clause 6.3.3. of the PDTR.
44  template<typename _Tp>
45  struct hash : public std::unary_function<_Tp, size_t>
46  {
47  size_t
48  operator()(_Tp __val) const;
49  };
50 
52  template<typename _Tp>
53  struct hash<_Tp*> : public std::unary_function<_Tp*, size_t>
54  {
55  size_t
56  operator()(_Tp* __p) const
57  { return reinterpret_cast<size_t>(__p); }
58  };
59 
61 #define _TR1_hashtable_define_trivial_hash(_Tp) \
62  template<> \
63  inline size_t \
64  hash<_Tp>::operator()(_Tp __val) const \
65  { return static_cast<size_t>(__val); }
66 
76  _TR1_hashtable_define_trivial_hash(unsigned short);
79  _TR1_hashtable_define_trivial_hash(unsigned long long);
80 
81 #undef _TR1_hashtable_define_trivial_hash
82 
83  // Fowler / Noll / Vo (FNV) Hash (type FNV-1a)
84  // (Used by the next specializations of std::tr1::hash.)
85 
87  template<size_t>
88  struct _Fnv_hash_base
89  {
90  template<typename _Tp>
91  static size_t
92  hash(const _Tp* __ptr, size_t __clength)
93  {
94  size_t __result = 0;
95  const char* __cptr = reinterpret_cast<const char*>(__ptr);
96  for (; __clength; --__clength)
97  __result = (__result * 131) + *__cptr++;
98  return __result;
99  }
100  };
101 
102  template<>
103  struct _Fnv_hash_base<4>
104  {
105  template<typename _Tp>
106  static size_t
107  hash(const _Tp* __ptr, size_t __clength)
108  {
109  size_t __result = static_cast<size_t>(2166136261UL);
110  const char* __cptr = reinterpret_cast<const char*>(__ptr);
111  for (; __clength; --__clength)
112  {
113  __result ^= static_cast<size_t>(*__cptr++);
114  __result *= static_cast<size_t>(16777619UL);
115  }
116  return __result;
117  }
118  };
119 
120  template<>
121  struct _Fnv_hash_base<8>
122  {
123  template<typename _Tp>
124  static size_t
125  hash(const _Tp* __ptr, size_t __clength)
126  {
127  size_t __result
128  = static_cast<size_t>(14695981039346656037ULL);
129  const char* __cptr = reinterpret_cast<const char*>(__ptr);
130  for (; __clength; --__clength)
131  {
132  __result ^= static_cast<size_t>(*__cptr++);
133  __result *= static_cast<size_t>(1099511628211ULL);
134  }
135  return __result;
136  }
137  };
138 
139  struct _Fnv_hash
140  : public _Fnv_hash_base<sizeof(size_t)>
141  {
142  using _Fnv_hash_base<sizeof(size_t)>::hash;
143 
144  template<typename _Tp>
145  static size_t
146  hash(const _Tp& __val)
147  { return hash(&__val, sizeof(__val)); }
148  };
149 
151  template<>
152  inline size_t
153  hash<float>::operator()(float __val) const
154  {
155  // 0 and -0 both hash to zero.
156  return __val != 0.0f ? std::tr1::_Fnv_hash::hash(__val) : 0;
157  }
158 
160  template<>
161  inline size_t
162  hash<double>::operator()(double __val) const
163  {
164  // 0 and -0 both hash to zero.
165  return __val != 0.0 ? std::tr1::_Fnv_hash::hash(__val) : 0;
166  }
167 
169  template<>
170  _GLIBCXX_PURE size_t
171  hash<long double>::operator()(long double __val) const;
172 
174  template<>
175  _GLIBCXX_PURE size_t
176  hash<string>::operator()(string) const;
177 
178  template<>
179  _GLIBCXX_PURE size_t
180  hash<const string&>::operator()(const string&) const;
181 
182 #ifdef _GLIBCXX_USE_WCHAR_T
183  template<>
184  _GLIBCXX_PURE size_t
185  hash<wstring>::operator()(wstring) const;
186 
187  template<>
188  _GLIBCXX_PURE size_t
189  hash<const wstring&>::operator()(const wstring&) const;
190 #endif
191 
192 _GLIBCXX_END_NAMESPACE_VERSION
193 }
194 }
#define _TR1_hashtable_define_trivial_hash(_Tp)