mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-13 16:21:53 +08:00
functional_hash.h (_Fnv_hash_base<>::hash): Change to template.
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. From-SVN: r157185
This commit is contained in:
parent
273e719b28
commit
055f6a476c
libstdc++-v3
@ -1,3 +1,13 @@
|
||||
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
|
||||
|
@ -2898,10 +2898,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
{
|
||||
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 */
|
||||
@ -2914,10 +2912,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
{
|
||||
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.
|
||||
@ -2927,10 +2923,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
{
|
||||
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
|
||||
|
||||
|
@ -122,45 +122,51 @@ namespace std
|
||||
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
|
||||
@ -171,14 +177,12 @@ namespace std
|
||||
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.
|
||||
@ -201,7 +205,7 @@ namespace std
|
||||
|
||||
/// Specialization for long double.
|
||||
template<>
|
||||
size_t
|
||||
_GLIBCXX_PURE size_t
|
||||
hash<long double>::operator()(long double __val) const;
|
||||
|
||||
// @} group hashes
|
||||
|
@ -694,10 +694,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
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;
|
||||
@ -706,13 +704,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
_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;
|
||||
|
@ -115,9 +115,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||
{ 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&
|
||||
@ -406,9 +406,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
|
||||
{ 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&
|
||||
@ -1501,8 +1501,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -85,47 +85,53 @@ namespace tr1
|
||||
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
|
||||
@ -136,8 +142,7 @@ namespace tr1
|
||||
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.
|
||||
|
@ -37,18 +37,12 @@
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user