diff --git a/include/boost/unordered/concurrent_flat_map.hpp b/include/boost/unordered/concurrent_flat_map.hpp index 04b69eaf..e3283a80 100644 --- a/include/boost/unordered/concurrent_flat_map.hpp +++ b/include/boost/unordered/concurrent_flat_map.hpp @@ -720,6 +720,26 @@ namespace boost { return merge(x); } + size_type count(key_type const& k) const { return table_.count(k); } + + template + typename std::enable_if< + detail::are_transparent::value, size_type>::type + count(K const& k) + { + return table_.count(k); + } + + bool contains(key_type const& k) const { return table_.contains(k); } + + template + typename std::enable_if< + detail::are_transparent::value, bool>::type + contains(K const& k) const + { + return table_.contains(k); + } + /// Hash Policy /// void rehash(size_type n) { table_.rehash(n); } diff --git a/test/cfoa/visit_tests.cpp b/test/cfoa/visit_tests.cpp index bc4fd13b..fae4deae 100644 --- a/test/cfoa/visit_tests.cpp +++ b/test/cfoa/visit_tests.cpp @@ -107,6 +107,45 @@ namespace { num_visits = 0; total_count = 0; } + + { + thread_runner(values, [&x, &total_count](boost::span s) { + for (auto const& val : s) { + auto r = val.first.x_; + BOOST_TEST(r >= 0); + + auto count = x.count(val.first); + BOOST_TEST_EQ(count, 1u); + total_count += count; + + count = x.count(val.second); + BOOST_TEST_EQ(count, 0u); + } + }); + + BOOST_TEST_EQ(total_count, values.size()); + + num_visits = 0; + total_count = 0; + } + + { + thread_runner(values, [&x](boost::span s) { + for (auto const& val : s) { + auto r = val.first.x_; + BOOST_TEST(r >= 0); + + auto contains = x.contains(val.first); + BOOST_TEST(contains); + + contains = x.contains(val.second); + BOOST_TEST(!contains); + } + }); + + num_visits = 0; + total_count = 0; + } } } lvalue_visitor; @@ -204,6 +243,45 @@ namespace { num_visits = 0; total_count = 0; } + + { + thread_runner(values, [&x, &total_count](boost::span s) { + for (auto const& val : s) { + auto r = val.first.x_; + BOOST_TEST(r >= 0); + + auto count = x.count(val.first.x_); + BOOST_TEST_EQ(count, 1u); + total_count += count; + + count = x.count(val.second.x_); + BOOST_TEST_EQ(count, 0u); + } + }); + + BOOST_TEST_EQ(total_count, values.size()); + + num_visits = 0; + total_count = 0; + } + + { + thread_runner(values, [&x](boost::span s) { + for (auto const& val : s) { + auto r = val.first.x_; + BOOST_TEST(r >= 0); + + auto contains = x.contains(val.first.x_); + BOOST_TEST(contains); + + contains = x.contains(val.second.x_); + BOOST_TEST(!contains); + } + }); + + num_visits = 0; + total_count = 0; + } } } transp_visitor; @@ -342,6 +420,7 @@ namespace { auto reference_map = boost::unordered_flat_map(values.begin(), values.end()); + raii::reset_counts(); {