Skip to content

Commit 664a0e6

Browse files
committed
fixed cfoa range insert functions to return the number of elements inserted instead of the size of the input range
1 parent df2dfe6 commit 664a0e6

5 files changed

Lines changed: 24 additions & 18 deletions

File tree

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: 12 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,16 @@ 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 s = x.size();
152+
std::atomic<std::uint64_t> num_inserts{0};
153+
thread_runner(values2, [&x, &num_inserts](boost::span<raii_convertible> s) {
154+
num_inserts += x.insert(s.begin(), s.begin() + s.size() / 2);
155+
num_inserts += x.insert(s.begin(), s.end());
153156
});
157+
BOOST_TEST_EQ(x.size(), s + num_inserts);
154158

155159
BOOST_TEST_EQ(
156-
raii::default_constructor, value_type_cardinality * values2.size());
160+
raii::default_constructor, value_type_cardinality * (values2.size() + values2.size() / 2));
157161
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 50300) && \
158162
BOOST_WORKAROUND(BOOST_GCC_VERSION, < 50500)
159163
// some versions of old gcc have trouble eliding copies here
@@ -1010,9 +1014,11 @@ namespace {
10101014
{
10111015
X x;
10121016

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

10171023
BOOST_TEST_EQ(x.size(), reference_cont.size());
10181024

0 commit comments

Comments
 (0)