Skip to content

Commit b00e7c4

Browse files
authored
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
1 parent df2dfe6 commit b00e7c4

7 files changed

Lines changed: 32 additions & 19 deletions

File tree

doc/modules/ROOT/pages/changes.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
:github-pr-url: https://github.com/boostorg/unordered/pull
77
:cpp: C++
88

9+
== Release 1.91.0
10+
11+
* Fixed the returned value of range insertion in concurrent containers
12+
({github-pr-url}/344[PR#344^]).
13+
914
== Release 1.89.0
1015

1116
* Deprecated `boost::unordered::hash_is_avalanching` is now a using-declaration of

doc/modules/ROOT/pages/copyright.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Copyright (C) 2005-2008 Daniel James
1111

1212
Copyright (C) 2022-2025 Christian Mazakas
1313

14-
Copyright (C) 2022-2025 Joaquín M López Muñoz
14+
Copyright (C) 2022-2026 Joaquín M López Muñoz
1515

1616
Copyright (C) 2022-2023 Peter Dimov
1717

include/boost/unordered/concurrent_flat_map.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Fast open-addressing concurrent hashmap.
22
*
33
* Copyright 2023 Christian Mazakas.
4-
* Copyright 2023-2024 Joaquin M Lopez Munoz.
4+
* Copyright 2023-2026 Joaquin M Lopez Munoz.
55
* Distributed under the Boost Software License, Version 1.0.
66
* (See accompanying file LICENSE_1_0.txt or copy at
77
* http://www.boost.org/LICENSE_1_0.txt)
@@ -423,8 +423,8 @@ namespace boost {
423423
size_type insert(InputIterator begin, InputIterator end)
424424
{
425425
size_type count_elements = 0;
426-
for (auto pos = begin; pos != end; ++pos, ++count_elements) {
427-
table_.emplace(*pos);
426+
for (auto pos = begin; pos != end; ++pos) {
427+
if (table_.emplace(*pos)) ++count_elements;
428428
}
429429
return count_elements;
430430
}

include/boost/unordered/concurrent_flat_set.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Fast open-addressing concurrent hashset.
22
*
33
* Copyright 2023 Christian Mazakas.
4-
* Copyright 2023-2024 Joaquin M Lopez Munoz.
4+
* Copyright 2023-2026 Joaquin M Lopez Munoz.
55
* Distributed under the Boost Software License, Version 1.0.
66
* (See accompanying file LICENSE_1_0.txt or copy at
77
* http://www.boost.org/LICENSE_1_0.txt)
@@ -429,8 +429,8 @@ namespace boost {
429429
size_type insert(InputIterator begin, InputIterator end)
430430
{
431431
size_type count_elements = 0;
432-
for (auto pos = begin; pos != end; ++pos, ++count_elements) {
433-
table_.emplace(*pos);
432+
for (auto pos = begin; pos != end; ++pos) {
433+
if (table_.emplace(*pos)) ++count_elements;
434434
}
435435
return count_elements;
436436
}

include/boost/unordered/concurrent_node_map.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Fast open-addressing, node-based concurrent hashmap.
22
*
33
* Copyright 2023 Christian Mazakas.
4-
* Copyright 2023-2024 Joaquin M Lopez Munoz.
4+
* Copyright 2023-2026 Joaquin M Lopez Munoz.
55
* Distributed under the Boost Software License, Version 1.0.
66
* (See accompanying file LICENSE_1_0.txt or copy at
77
* http://www.boost.org/LICENSE_1_0.txt)
@@ -430,8 +430,8 @@ namespace boost {
430430
size_type insert(InputIterator begin, InputIterator end)
431431
{
432432
size_type count_elements = 0;
433-
for (auto pos = begin; pos != end; ++pos, ++count_elements) {
434-
table_.emplace(*pos);
433+
for (auto pos = begin; pos != end; ++pos) {
434+
if (table_.emplace(*pos)) ++count_elements;
435435
}
436436
return count_elements;
437437
}

include/boost/unordered/concurrent_node_set.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Fast open-addressing, node-based concurrent hashset.
22
*
33
* Copyright 2023 Christian Mazakas.
4-
* Copyright 2023-2024 Joaquin M Lopez Munoz.
4+
* Copyright 2023-2026 Joaquin M Lopez Munoz.
55
* Distributed under the Boost Software License, Version 1.0.
66
* (See accompanying file LICENSE_1_0.txt or copy at
77
* http://www.boost.org/LICENSE_1_0.txt)
@@ -436,8 +436,8 @@ namespace boost {
436436
size_type insert(InputIterator begin, InputIterator end)
437437
{
438438
size_type count_elements = 0;
439-
for (auto pos = begin; pos != end; ++pos, ++count_elements) {
440-
table_.emplace(*pos);
439+
for (auto pos = begin; pos != end; ++pos) {
440+
if (table_.emplace(*pos)) ++count_elements;
441441
}
442442
return count_elements;
443443
}

test/cfoa/insert_tests.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (C) 2023 Christian Mazakas
2-
// Copyright (C) 2023-2024 Joaquin M Lopez Munoz
2+
// Copyright (C) 2023-2026 Joaquin M Lopez Munoz
33
// Distributed under the Boost Software License, Version 1.0. (See accompanying
44
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
55

@@ -148,12 +148,18 @@ namespace {
148148
values2.push_back(raii_convertible(v));
149149
}
150150

151-
thread_runner(values2, [&x](boost::span<raii_convertible> s) {
152-
BOOST_TEST_EQ(x.insert(s.begin(), s.end()), s.size());
151+
auto sz = x.size();
152+
std::atomic<std::uint64_t> num_inserts{0};
153+
std::atomic<std::uint64_t> num_attempted_inserts{0};
154+
thread_runner(values2, [&x, &num_inserts, &num_attempted_inserts](boost::span<raii_convertible> s) {
155+
num_inserts += x.insert(s.begin(), s.begin() + s.size() / 2);
156+
num_inserts += x.insert(s.begin(), s.end());
157+
num_attempted_inserts += s.size() + s.size() / 2;
153158
});
159+
BOOST_TEST_EQ(x.size(), sz + num_inserts);
154160

155161
BOOST_TEST_EQ(
156-
raii::default_constructor, value_type_cardinality * values2.size());
162+
raii::default_constructor, value_type_cardinality * num_attempted_inserts);
157163
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
158164
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)
159165
// some versions of old gcc have trouble eliding copies here
@@ -1010,9 +1016,11 @@ namespace {
10101016
{
10111017
X x;
10121018

1013-
thread_runner(dummy, [&x, &init_list](boost::span<raii>) {
1014-
BOOST_TEST_EQ(x.insert(init_list), init_list.size());
1019+
std::atomic<std::uint64_t> num_inserts{0};
1020+
thread_runner(dummy, [&x, &init_list, &num_inserts](boost::span<raii>) {
1021+
num_inserts += x.insert(init_list);
10151022
});
1023+
BOOST_TEST_EQ(num_inserts, x.size());
10161024

10171025
BOOST_TEST_EQ(x.size(), reference_cont.size());
10181026

0 commit comments

Comments
 (0)