aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs
diff options
context:
space:
mode:
authorhalyavin <halyavin@yandex-team.com>2023-01-18 12:54:01 +0300
committerhalyavin <halyavin@yandex-team.com>2023-01-18 12:54:01 +0300
commitc4bd4bb84b7a682445ae8aa4b725a02017e5e7ff (patch)
tree19c6b2543027a3cb8730c6d5fd9ddb9a05251c96 /contrib/libs
parent19923d1d116cc3714b8aeb02b0a4bdec86f87e7d (diff)
downloadydb-c4bd4bb84b7a682445ae8aa4b725a02017e5e7ff.tar.gz
Add std::hash<std::vector<bool>> implementation required by the standard.
Diffstat (limited to 'contrib/libs')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/vector27
1 files changed, 26 insertions, 1 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/vector b/contrib/libs/cxxsupp/libcxx/include/vector
index 1a2a271058..9f5e57f454 100644
--- a/contrib/libs/cxxsupp/libcxx/include/vector
+++ b/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