Skip to content

Commit e596f42

Browse files
refactor: Replace phmap with boost.unordered
Minimize dependence on external projects by dropping `parallel-hashmap` and replacing it with `boost-unordered`. `boost-unordered` provides a fast `unordered_map` implementation since `1.80` and an even faster `unordered_flat_map` since `1.81`. Therefore we bump the required version. Properly assert the required version during CMake configuration as well as during transitive dependency lookup.
1 parent 485177f commit e596f42

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ mark_as_advanced(DPLX_DP_USE_BRANCHING_INTEGER_ENCODER)
5858

5959
set(Boost_NO_WARN_NEW_VERSIONS ON)
6060

61-
find_package(concrete CONFIG REQUIRED)
61+
find_package(concrete 0.0 CONFIG REQUIRED)
6262

63-
find_package(fmt CONFIG REQUIRED)
63+
find_package(fmt 9 CONFIG REQUIRED)
6464

6565
find_package(status-code CONFIG REQUIRED)
6666
find_package(outcome CONFIG REQUIRED)
6767

68-
find_package(Boost 1.71 REQUIRED)
68+
find_package(Boost 1.81 REQUIRED)
6969

7070
find_package(yaml-cpp CONFIG)
7171
set_package_properties(yaml-cpp PROPERTIES

src/dplx/dp/detail/workaround.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#pragma once
99

10+
#include <dplx/predef/library/std.h>
1011
#include <dplx/predef/version_number.h>
1112
#include <dplx/predef/workaround.h>
1213

@@ -27,3 +28,10 @@
2728
DPLX_XDEF_WORKAROUND_TESTED_AT(DPLX_DP_DISABLE_WORKAROUNDS, \
2829
DPLX_DP_FLAG_OUTDATED_WORKAROUNDS, symbol, \
2930
major, minor, patch)
31+
32+
////////////////////////////////////////////////////////////////////////////////
33+
34+
// libstdc++ fails to forward pair members during uses_allocator construction
35+
// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108952
36+
#define DPLX_DP_WORKAROUND_ISSUE_LIBSTDCPP_108952 \
37+
DPLX_DP_WORKAROUND_TESTED_AT(DPLX_LIB_STD_GNU, 12, 2, 0)

src/dplx/dp/state.hpp

+18-12
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
#include <memory_resource>
1212
#include <utility>
1313

14-
#include <parallel_hashmap/phmap.h>
14+
#include <boost/unordered/unordered_flat_map.hpp>
1515

1616
#include <dplx/cncr/utils.hpp>
1717
#include <dplx/cncr/uuid.hpp>
1818

19+
#include <dplx/dp/detail/workaround.hpp>
1920
#include <dplx/dp/fwd.hpp>
2021

2122
namespace dplx::dp::detail
@@ -121,6 +122,13 @@ class unique_erased_state_ptr
121122
, mDelete(std::exchange(other.mDelete, nullptr))
122123
{
123124
}
125+
#if DPLX_DP_WORKAROUND_ISSUE_LIBSTDCPP_108952
126+
constexpr unique_erased_state_ptr(unique_erased_state_ptr &other) noexcept
127+
: mObj(std::exchange(other.mObj, nullptr))
128+
, mDelete(std::exchange(other.mDelete, nullptr))
129+
{
130+
}
131+
#endif
124132
constexpr auto operator=(unique_erased_state_ptr &&other) noexcept
125133
-> unique_erased_state_ptr &
126134
{
@@ -195,7 +203,7 @@ namespace dplx::dp::detail
195203
{
196204

197205
template <typename Key, typename T>
198-
using flat_hash_map = phmap::flat_hash_map<
206+
using flat_hash_map = boost::unordered_flat_map<
199207
Key,
200208
T,
201209
std::hash<Key>,
@@ -278,14 +286,14 @@ class state_store
278286
auto emplace(state_key<StateT> const &key, Args &&...args)
279287
-> std::pair<StateT *, bool>
280288
{
281-
auto const h = mImpl.hash(key.value);
282-
if (auto it = mImpl.find(key.value, h); it != mImpl.end())
289+
auto hint = mImpl.find(key.value);
290+
if (hint != mImpl.end())
283291
{
284292
// this way, we don't need to allocate if key already has a value
285-
return {it->second.template get<StateT>(), false};
293+
return {hint->second.template get<StateT>(), false};
286294
}
287-
auto [it, emplaced] = mImpl.emplace_with_hash(
288-
h, key.value,
295+
auto it = mImpl.emplace_hint(
296+
hint, key.value,
289297
detail::allocate_state<StateT, allocator_type>(
290298
mImpl.get_allocator(), static_cast<Args &&>(args)...));
291299
return {it->second.template get<StateT>(), true};
@@ -401,15 +409,13 @@ class link_store
401409
template <state_link T>
402410
auto replace(state_link_key<T> const &key, T value) -> T
403411
{
404-
auto const h = mImpl.hash(key.value);
405-
auto it = mImpl.find(key.value, h);
412+
auto it = mImpl.find(key.value);
406413
if (it == mImpl.end())
407414
{
408415
if (value != T{})
409416
{
410-
mImpl.emplace_with_hash(
411-
h, key.value,
412-
detail::erasure_cast<erased_type, T>(value));
417+
mImpl.emplace_hint(it, key.value,
418+
detail::erasure_cast<erased_type, T>(value));
413419
}
414420
return T{};
415421
}

tools/deeppack-config.cmake.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
@PACKAGE_INIT@
22

33
include(CMakeFindDependencyMacro)
4-
find_dependency(Boost)
5-
find_dependency(fmt)
4+
find_dependency(Boost 1.81)
5+
find_dependency(fmt 9)
6+
find_dependency(status-code)
67
find_dependency(outcome)
7-
find_dependency(concrete)
8+
find_dependency(concrete 0.0)
89

910
include("${CMAKE_CURRENT_LIST_DIR}/deeppack-targets.cmake")
1011

vcpkg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"boost-endian",
88
"boost-container",
99
"boost-mp11",
10+
"boost-unordered",
1011
"concrete",
1112
"fmt",
1213
"outcome",
13-
"parallel-hashmap",
1414
"status-code"
1515
],
1616
"features": {

0 commit comments

Comments
 (0)