]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
functional_hash.h (_Fnv_hash_base<>::hash): Change to template.
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 3 Mar 2010 01:23:07 +0000 (01:23 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 3 Mar 2010 01:23:07 +0000 (01:23 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/functional_hash.h
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/include/std/bitset
libstdc++-v3/include/tr1/functional_hash.h
libstdc++-v3/src/hash-string-aux.cc

index 86e26475f51d200d4ce31e909743678da95915ec..f8c19e4d3aa05d55de305999d55aeff3543c284b 100644 (file)
@@ -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
index 4c1c427f1429deac89c0b621763a99f3c08d1a91..312d4ed6cb6a9bfa0eb72af707945bdf851f892b 100644 (file)
@@ -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
 
index 41fe11fae8f5f9055eae66c6ae62ed4ca9940178..aaa05aad689c13147fbf282461602bbd7b94f47b 100644 (file)
@@ -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
index 984f83f3c9ebf0450e3f85a255baea2cbb374b05..e10979310489c40deaee2898535c6c780ac2d607 100644 (file)
@@ -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;
index 7372639c58a85362001902085c6c44386efb73e4..b23b51a78fed40dd5990f306b06c69fbcfbf7f03 100644 (file)
@@ -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);
       }
     };
 
index 98fb187869516651d1177e8e92a44200cc826474..9ea483e3e38eec2b490e0beffc5b39fa276340f5 100644 (file)
@@ -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.
index b5a2c6ddc3da815d8e0ccb9e62fc32a11574e162..711d7f41c9d314b7c8ad4d0f345828106fa5c318 100644 (file)
   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