Skip to content

Commit

Permalink
implemented proper stats handling on concurrent<->unordered move cons…
Browse files Browse the repository at this point in the history
…truction
  • Loading branch information
joaquintides committed May 3, 2024
1 parent 37451ec commit 223f647
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/boost/unordered/detail/foa/concurrent_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ class concurrent_table:
x.arrays=ah.release();
x.size_ctrl.ml=x.initial_max_load();
x.size_ctrl.size=0;
BOOST_UNORDERED_SWAP_STATS(
this->get_cumulative_stats(),x.get_cumulative_stats());
}

concurrent_table(compatible_nonconcurrent_table&& x):
Expand Down
4 changes: 3 additions & 1 deletion include/boost/unordered/detail/foa/table.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Fast open-addressing hash table.
*
* Copyright 2022-2023 Joaquin M Lopez Munoz.
* Copyright 2022-2024 Joaquin M Lopez Munoz.
* Copyright 2023 Christian Mazakas.
* Copyright 2024 Braden Ganetsky.
* Distributed under the Boost Software License, Version 1.0.
Expand Down Expand Up @@ -593,6 +593,8 @@ class table:table_core_impl<TypePolicy,Hash,Pred,Allocator>
x.arrays=ah.release();
x.size_ctrl.ml=x.initial_max_load();
x.size_ctrl.size=0;
BOOST_UNORDERED_SWAP_STATS(
this->get_cumulative_stats(),x.get_cumulative_stats());
}

template<typename ExclusiveLockGuard>
Expand Down
26 changes: 25 additions & 1 deletion test/unordered/stats_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifdef BOOST_UNORDERED_CFOA_TESTS
#include <boost/unordered/concurrent_flat_map.hpp>
#include <boost/unordered/concurrent_flat_set.hpp>
#include <boost/unordered/unordered_flat_map.hpp>
#include <boost/unordered/unordered_flat_set.hpp>
#include "../cfoa/helpers.hpp"
#else
#include "../helpers/unordered.hpp"
Expand Down Expand Up @@ -302,9 +304,25 @@ template <class Container> void test_stats()
check_insertion_stats(c7.get_stats().insertion, stats_full);
check_lookup_stats(c7.get_stats().successful_lookup, stats_empty);
check_lookup_stats(c7.get_stats().unsuccessful_lookup, stats_empty);
}

// TODO: concurrent<->unordered interop
#if defined(BOOST_UNORDERED_CFOA_TESTS)
template <class Container, class ConcurrentContainer>
void test_stats_concurrent_unordered_interop()
{
ConcurrentContainer cc1;
insert_n(cc1,5000);
insert_n(cc1,5000); // produces successful lookups
auto s=cc1.get_stats();
Container c1(std::move(cc1));
check_container_stats(cc1.get_stats(),stats_empty);
check_container_stats(c1.get_stats(),s);

ConcurrentContainer cc2(std::move(c1));
check_container_stats(c1.get_stats(),stats_empty);
check_container_stats(cc2.get_stats(),s);
}
#endif

UNORDERED_AUTO_TEST (stats_) {
#if defined(BOOST_UNORDERED_CFOA_TESTS)
Expand All @@ -315,6 +333,12 @@ UNORDERED_AUTO_TEST (stats_) {
test_stats<
boost::concurrent_flat_set<
int, boost::hash<int>, std::equal_to<int>, unequal_allocator<int>>>();
test_stats_concurrent_unordered_interop<
boost::unordered_flat_map<int, int>,
boost::concurrent_flat_map<int, int>>();
test_stats_concurrent_unordered_interop<
boost::unordered_flat_set<int>,
boost::concurrent_flat_set<int>>();
#elif defined(BOOST_UNORDERED_FOA_TESTS)
test_stats<
boost::unordered_flat_map<
Expand Down

0 comments on commit 223f647

Please sign in to comment.