Browse Source

Add std::hash<std::vector<bool>> implementation required by the standard.

halyavin 2 years ago
parent
commit
c4bd4bb84b
1 changed files with 26 additions and 1 deletions
  1. 26 1
      contrib/libs/cxxsupp/libcxx/include/vector

+ 26 - 1
contrib/libs/cxxsupp/libcxx/include/vector

@@ -3281,7 +3281,32 @@ struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
     size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
         {return __vec.__hash_code();}
 };
-#endif // _YNDX_LIBCXX_DISABLE_VECTOR_BOOL_COMPRESSION
+#else // _YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION
+// Hash function implementation for uncompressed std::vector<bool> which returns the same result.
+template <class _Allocator>
+struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
+    : public unary_function<vector<bool, _Allocator>, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
+    {
+        size_t __h = 0;
+        size_t __idx = 0;
+        size_t __n = __vec.size();
+        constexpr size_t __bits_per_word = sizeof(typename allocator_traits<_Allocator>::size_type) * CHAR_BIT;
+        static_assert(sizeof(typename allocator_traits<_Allocator>::size_type) <= sizeof(size_t));
+        for (;__idx + __bits_per_word <= __n;) {
+            for (size_t __bit = 0; __bit < __bits_per_word; __bit++, __idx++) {
+                __h ^= static_cast<size_t>(__vec[__idx]) << __bit;
+            }
+        }
+        for (size_t __bit = 0; __idx < __n; __bit++, __idx++) {
+            __h ^= static_cast<size_t>(__vec[__idx]) << __bit;
+        }
+        return __h;
+    }
+};
+#endif // _YNDX_LIBCXX_ENABLE_VECTOR_BOOL_COMPRESSION
 
 template <class _Tp, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY