fixed cfoa range insert functions to return the number of elements inserted instead of the size of the input range (#344)

* fixed cfoa range insert functions to return the number of elements inserted instead of the size of the input range

* avoided variable shadowing

* fixed calculation error in test

* updated release notes
This commit is contained in:
joaquintides
2026-02-14 18:08:20 +01:00
committed by GitHub
parent df2dfe6140
commit b00e7c4624
7 changed files with 32 additions and 19 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<raii_convertible> s) {
BOOST_TEST_EQ(x.insert(s.begin(), s.end()), s.size());
auto sz = x.size();
std::atomic<std::uint64_t> num_inserts{0};
std::atomic<std::uint64_t> num_attempted_inserts{0};
thread_runner(values2, [&x, &num_inserts, &num_attempted_inserts](boost::span<raii_convertible> 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<raii>) {
BOOST_TEST_EQ(x.insert(init_list), init_list.size());
std::atomic<std::uint64_t> num_inserts{0};
thread_runner(dummy, [&x, &init_list, &num_inserts](boost::span<raii>) {
num_inserts += x.insert(init_list);
});
BOOST_TEST_EQ(num_inserts, x.size());
BOOST_TEST_EQ(x.size(), reference_cont.size());