diff --git a/doc/modules/ROOT/pages/changes.adoc b/doc/modules/ROOT/pages/changes.adoc index bd801bf4..99532bbf 100644 --- a/doc/modules/ROOT/pages/changes.adoc +++ b/doc/modules/ROOT/pages/changes.adoc @@ -6,6 +6,11 @@ :github-pr-url: https://github.com/boostorg/unordered/pull :cpp: C++ +== Release 1.91.0 + +* Fixed the returned value of range insertion in concurrent containers +({github-pr-url}/344[PR#344^]). + == Release 1.89.0 * Deprecated `boost::unordered::hash_is_avalanching` is now a using-declaration of diff --git a/doc/modules/ROOT/pages/copyright.adoc b/doc/modules/ROOT/pages/copyright.adoc index 43a906a4..4c80f269 100644 --- a/doc/modules/ROOT/pages/copyright.adoc +++ b/doc/modules/ROOT/pages/copyright.adoc @@ -11,7 +11,7 @@ Copyright (C) 2005-2008 Daniel James Copyright (C) 2022-2025 Christian Mazakas -Copyright (C) 2022-2025 Joaquín M López Muñoz +Copyright (C) 2022-2026 Joaquín M López Muñoz Copyright (C) 2022-2023 Peter Dimov diff --git a/include/boost/unordered/concurrent_flat_map.hpp b/include/boost/unordered/concurrent_flat_map.hpp index 77445d18..6b54ce5e 100644 --- a/include/boost/unordered/concurrent_flat_map.hpp +++ b/include/boost/unordered/concurrent_flat_map.hpp @@ -1,7 +1,7 @@ /* Fast open-addressing concurrent hashmap. * * Copyright 2023 Christian Mazakas. - * Copyright 2023-2024 Joaquin M Lopez Munoz. + * Copyright 2023-2026 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -423,8 +423,8 @@ namespace boost { size_type insert(InputIterator begin, InputIterator end) { size_type count_elements = 0; - for (auto pos = begin; pos != end; ++pos, ++count_elements) { - table_.emplace(*pos); + for (auto pos = begin; pos != end; ++pos) { + if (table_.emplace(*pos)) ++count_elements; } return count_elements; } diff --git a/include/boost/unordered/concurrent_flat_set.hpp b/include/boost/unordered/concurrent_flat_set.hpp index f0f44308..54cb6c9f 100644 --- a/include/boost/unordered/concurrent_flat_set.hpp +++ b/include/boost/unordered/concurrent_flat_set.hpp @@ -1,7 +1,7 @@ /* Fast open-addressing concurrent hashset. * * Copyright 2023 Christian Mazakas. - * Copyright 2023-2024 Joaquin M Lopez Munoz. + * Copyright 2023-2026 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -429,8 +429,8 @@ namespace boost { size_type insert(InputIterator begin, InputIterator end) { size_type count_elements = 0; - for (auto pos = begin; pos != end; ++pos, ++count_elements) { - table_.emplace(*pos); + for (auto pos = begin; pos != end; ++pos) { + if (table_.emplace(*pos)) ++count_elements; } return count_elements; } diff --git a/include/boost/unordered/concurrent_node_map.hpp b/include/boost/unordered/concurrent_node_map.hpp index 1b6f1623..e75f9659 100644 --- a/include/boost/unordered/concurrent_node_map.hpp +++ b/include/boost/unordered/concurrent_node_map.hpp @@ -1,7 +1,7 @@ /* Fast open-addressing, node-based concurrent hashmap. * * Copyright 2023 Christian Mazakas. - * Copyright 2023-2024 Joaquin M Lopez Munoz. + * Copyright 2023-2026 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -430,8 +430,8 @@ namespace boost { size_type insert(InputIterator begin, InputIterator end) { size_type count_elements = 0; - for (auto pos = begin; pos != end; ++pos, ++count_elements) { - table_.emplace(*pos); + for (auto pos = begin; pos != end; ++pos) { + if (table_.emplace(*pos)) ++count_elements; } return count_elements; } diff --git a/include/boost/unordered/concurrent_node_set.hpp b/include/boost/unordered/concurrent_node_set.hpp index 430bc079..71818f96 100644 --- a/include/boost/unordered/concurrent_node_set.hpp +++ b/include/boost/unordered/concurrent_node_set.hpp @@ -1,7 +1,7 @@ /* Fast open-addressing, node-based concurrent hashset. * * Copyright 2023 Christian Mazakas. - * Copyright 2023-2024 Joaquin M Lopez Munoz. + * Copyright 2023-2026 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -436,8 +436,8 @@ namespace boost { size_type insert(InputIterator begin, InputIterator end) { size_type count_elements = 0; - for (auto pos = begin; pos != end; ++pos, ++count_elements) { - table_.emplace(*pos); + for (auto pos = begin; pos != end; ++pos) { + if (table_.emplace(*pos)) ++count_elements; } return count_elements; } diff --git a/test/cfoa/insert_tests.cpp b/test/cfoa/insert_tests.cpp index 114234af..985f9a40 100644 --- a/test/cfoa/insert_tests.cpp +++ b/test/cfoa/insert_tests.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2023 Christian Mazakas -// Copyright (C) 2023-2024 Joaquin M Lopez Munoz +// Copyright (C) 2023-2026 Joaquin M Lopez Munoz // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -148,12 +148,18 @@ namespace { values2.push_back(raii_convertible(v)); } - thread_runner(values2, [&x](boost::span s) { - BOOST_TEST_EQ(x.insert(s.begin(), s.end()), s.size()); + auto sz = x.size(); + std::atomic num_inserts{0}; + std::atomic num_attempted_inserts{0}; + thread_runner(values2, [&x, &num_inserts, &num_attempted_inserts](boost::span s) { + num_inserts += x.insert(s.begin(), s.begin() + s.size() / 2); + num_inserts += x.insert(s.begin(), s.end()); + num_attempted_inserts += s.size() + s.size() / 2; }); + BOOST_TEST_EQ(x.size(), sz + num_inserts); BOOST_TEST_EQ( - raii::default_constructor, value_type_cardinality * values2.size()); + raii::default_constructor, value_type_cardinality * num_attempted_inserts); #if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \ BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500) // some versions of old gcc have trouble eliding copies here @@ -1010,9 +1016,11 @@ namespace { { X x; - thread_runner(dummy, [&x, &init_list](boost::span) { - BOOST_TEST_EQ(x.insert(init_list), init_list.size()); + std::atomic num_inserts{0}; + thread_runner(dummy, [&x, &init_list, &num_inserts](boost::span) { + num_inserts += x.insert(init_list); }); + BOOST_TEST_EQ(num_inserts, x.size()); BOOST_TEST_EQ(x.size(), reference_cont.size());