diff --git a/include/ygm/container/map.hpp b/include/ygm/container/map.hpp index c37384aa..5479d6be 100644 --- a/include/ygm/container/map.hpp +++ b/include/ygm/container/map.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,8 @@ class map public detail::base_contains, std::tuple>, public detail::base_count, std::tuple>, public detail::base_async_reduce, std::tuple>, + public detail::base_async_contains, + std::tuple>, public detail::base_async_erase_key, std::tuple>, public detail::base_async_erase_key_value, diff --git a/test/test_map.cpp b/test/test_map.cpp index 36cd1f95..abdca12f 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -301,6 +301,39 @@ int main(int argc, char **argv) { YGM_ASSERT_RELEASE(!smap.contains("blue")); } + // + // Test async_contains + { + ygm::container::map smap(world); + + smap.async_insert("dog", "cat"); + smap.async_insert("apple", "orange"); + + world.barrier(); + + auto contains_key_functor = [](const bool is_present, + const std::string &key, + const std::string &sent_key) { + YGM_ASSERT_RELEASE(key == sent_key); + YGM_ASSERT_RELEASE(is_present == true); + }; + + auto does_not_contain_key_functor = [](const bool is_present, + const std::string &key, + const std::string &sent_key) { + YGM_ASSERT_RELEASE(key == sent_key); + YGM_ASSERT_RELEASE(is_present == false); + }; + + smap.async_contains("dog", contains_key_functor, std::string("dog")); + smap.async_contains("apple", contains_key_functor, std::string("apple")); + + smap.async_contains("fish", does_not_contain_key_functor, + std::string("fish")); + smap.async_contains("tomato", does_not_contain_key_functor, + std::string("tomato")); + } + // Test batch erase from set { int num_items = 100;