+2010-03-02 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/functional_hash.h (_Fnv_hash_base<>::hash): Change
+ to template.
+ * include/tr1/functional_hash.h (_Fnv_hash_base<>::hash): Likewise.
+ * include/bits/vector.tcc (hash): Adjust.
+ * include/bits/basic_string.h (hash): Likewise.
+ * include/std/bitset (hash): Likewise.
+ * src/hash-string-aux.cc (hash): Likewise.
+
2010-03-02 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/std/mutex (lock_guard::lock_guard): Do not lock mutex when
{
size_t
operator()(const wstring& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(wchar_t)); }
};
#endif
#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
{
size_t
operator()(const u16string& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(char16_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char16_t)); }
};
/// std::hash specialization for u32string.
{
size_t
operator()(const u32string& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return std::_Fnv_hash::hash(__p, __s.length() * sizeof(char32_t));
- }
+ { return std::_Fnv_hash::hash(__s.data(),
+ __s.length() * sizeof(char32_t)); }
};
#endif
template<size_t>
struct _Fnv_hash_base
{
- static size_t
- hash(const char* __first, size_t __length, size_t __hash = 0)
- {
- for (; __length; --__length)
- __hash = (__hash * 131) + *__first++;
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength, size_t __hash = 0)
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ __hash = (__hash * 131) + *__cptr++;
+ return __hash;
+ }
};
template<>
struct _Fnv_hash_base<4>
{
- static size_t
- hash(const char* __first, size_t __length,
- size_t __hash = static_cast<size_t>(2166136261UL))
- {
- for (; __length; --__length)
- {
- __hash ^= static_cast<size_t>(*__first++);
- __hash *= static_cast<size_t>(16777619UL);
- }
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength,
+ size_t __hash = static_cast<size_t>(2166136261UL))
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __hash ^= static_cast<size_t>(*__cptr++);
+ __hash *= static_cast<size_t>(16777619UL);
+ }
+ return __hash;
+ }
};
template<>
struct _Fnv_hash_base<8>
{
- static size_t
- hash(const char* __first, size_t __length,
- size_t __hash = static_cast<size_t>(14695981039346656037ULL))
- {
- for (; __length; --__length)
- {
- __hash ^= static_cast<size_t>(*__first++);
- __hash *= static_cast<size_t>(1099511628211ULL);
- }
- return __hash;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength,
+ size_t __hash = static_cast<size_t>(14695981039346656037ULL))
+ {
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __hash ^= static_cast<size_t>(*__cptr++);
+ __hash *= static_cast<size_t>(1099511628211ULL);
+ }
+ return __hash;
+ }
};
struct _Fnv_hash
template<typename _Tp>
static size_t
hash(const _Tp& __val)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val)); }
+ { return hash(&__val, sizeof(__val)); }
template<typename _Tp>
static size_t
__hash_combine(const _Tp& __val, size_t __hash)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val), __hash); }
+ { return hash(&__val, sizeof(__val), __hash); }
};
/// Specialization for float.
/// Specialization for long double.
template<>
- size_t
+ _GLIBCXX_PURE size_t
hash<long double>::operator()(long double __val) const;
// @} group hashes
const size_t __words = __b.size() / _S_word_bit;
if (__words)
{
- const char* __data
- = reinterpret_cast<const char*>(__b._M_impl._M_start._M_p);
- const size_t __size = __words * sizeof(_Bit_type);
- __hash = std::_Fnv_hash::hash(__data, __size);
+ const size_t __clength = __words * sizeof(_Bit_type);
+ __hash = std::_Fnv_hash::hash(__b._M_impl._M_start._M_p, __clength);
}
const size_t __extrabits = __b.size() % _S_word_bit;
_Bit_type __hiword = *__b._M_impl._M_finish._M_p;
__hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits);
- const char* __data = reinterpret_cast<const char*>(&__hiword);
- const size_t __size
+ const size_t __clength
= (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__;
if (__words)
- __hash = std::_Fnv_hash::hash(__data, __size, __hash);
+ __hash = std::_Fnv_hash::hash(&__hiword, __clength, __hash);
else
- __hash = std::_Fnv_hash::hash(__data, __size);
+ __hash = std::_Fnv_hash::hash(&__hiword, __clength);
}
return __hash;
{ return _M_w[_S_whichword(__pos)]; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- const char*
+ const _WordT*
_M_getdata() const
- { return reinterpret_cast<const char*>(_M_w); }
+ { return _M_w; }
#endif
_WordT&
{ return _M_w; }
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- const char*
+ const _WordT*
_M_getdata() const
- { return reinterpret_cast<const char*>(&_M_w); }
+ { return &_M_w; }
#endif
_WordT&
size_t
operator()(const _GLIBCXX_STD_D::bitset<_Nb>& __b) const
{
- const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
- return std::_Fnv_hash::hash(__b._M_getdata(), __size);
+ const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+ return std::_Fnv_hash::hash(__b._M_getdata(), __clength);
}
};
template<size_t>
struct _Fnv_hash_base
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result = 0;
- for (; __length > 0; --__length)
- __result = (__result * 131) + *__first++;
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result = 0;
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ __result = (__result * 131) + *__cptr++;
+ return __result;
+ }
};
template<>
struct _Fnv_hash_base<4>
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result = static_cast<size_t>(2166136261UL);
- for (; __length > 0; --__length)
- {
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(16777619UL);
- }
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result = static_cast<size_t>(2166136261UL);
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __result ^= static_cast<size_t>(*__cptr++);
+ __result *= static_cast<size_t>(16777619UL);
+ }
+ return __result;
+ }
};
template<>
struct _Fnv_hash_base<8>
{
- static size_t
- hash(const char* __first, size_t __length)
- {
- size_t __result =
- static_cast<size_t>(14695981039346656037ULL);
- for (; __length > 0; --__length)
- {
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(1099511628211ULL);
- }
- return __result;
- }
+ template<typename _Tp>
+ static size_t
+ hash(const _Tp* __ptr, size_t __clength)
+ {
+ size_t __result
+ = static_cast<size_t>(14695981039346656037ULL);
+ const char* __cptr = reinterpret_cast<const char*>(__ptr);
+ for (; __clength; --__clength)
+ {
+ __result ^= static_cast<size_t>(*__cptr++);
+ __result *= static_cast<size_t>(1099511628211ULL);
+ }
+ return __result;
+ }
};
struct _Fnv_hash
template<typename _Tp>
static size_t
hash(const _Tp& __val)
- { return hash(reinterpret_cast<const char*>(&__val),
- sizeof(__val)); }
+ { return hash(&__val, sizeof(__val)); }
};
/// Explicit specializations for float.
template<>
size_t
hash<wstring>::operator()(wstring __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return _Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return _Fnv_hash::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
template<>
size_t
hash<const wstring&>::operator()(const wstring& __s) const
- {
- const char* __p = reinterpret_cast<const char*>(__s.data());
- return _Fnv_hash::hash(__p, __s.length() * sizeof(wchar_t));
- }
+ { return _Fnv_hash::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
#endif
#endif