forked from boostorg/unordered
Add count(), contains()
This commit is contained in:
@ -720,6 +720,26 @@ namespace boost {
|
|||||||
return merge(x);
|
return merge(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_type count(key_type const& k) const { return table_.count(k); }
|
||||||
|
|
||||||
|
template <class K>
|
||||||
|
typename std::enable_if<
|
||||||
|
detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
|
||||||
|
count(K const& k)
|
||||||
|
{
|
||||||
|
return table_.count(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(key_type const& k) const { return table_.contains(k); }
|
||||||
|
|
||||||
|
template <class K>
|
||||||
|
typename std::enable_if<
|
||||||
|
detail::are_transparent<K, hasher, key_equal>::value, bool>::type
|
||||||
|
contains(K const& k) const
|
||||||
|
{
|
||||||
|
return table_.contains(k);
|
||||||
|
}
|
||||||
|
|
||||||
/// Hash Policy
|
/// Hash Policy
|
||||||
///
|
///
|
||||||
void rehash(size_type n) { table_.rehash(n); }
|
void rehash(size_type n) { table_.rehash(n); }
|
||||||
|
@ -107,6 +107,45 @@ namespace {
|
|||||||
num_visits = 0;
|
num_visits = 0;
|
||||||
total_count = 0;
|
total_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
thread_runner(values, [&x, &total_count](boost::span<T> 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<T> 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;
|
} lvalue_visitor;
|
||||||
|
|
||||||
@ -204,6 +243,45 @@ namespace {
|
|||||||
num_visits = 0;
|
num_visits = 0;
|
||||||
total_count = 0;
|
total_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
thread_runner(values, [&x, &total_count](boost::span<T> 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<T> 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;
|
} transp_visitor;
|
||||||
|
|
||||||
@ -342,6 +420,7 @@ namespace {
|
|||||||
|
|
||||||
auto reference_map =
|
auto reference_map =
|
||||||
boost::unordered_flat_map<raii, raii>(values.begin(), values.end());
|
boost::unordered_flat_map<raii, raii>(values.begin(), values.end());
|
||||||
|
|
||||||
raii::reset_counts();
|
raii::reset_counts();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user