Skip to content

Commit 48702be

Browse files
authored
Merge pull request TheHPXProject#6897 from guptapratykshh/concurrent-data-structures
Implement concurrent data structures for Issue TheHPXProject#2235
2 parents f2ed87b + 0adb5f4 commit 48702be

14 files changed

Lines changed: 2036 additions & 1 deletion

cmake/HPX_AddConfigTest.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,24 @@ function(hpx_check_for_mm_prefetch)
695695
)
696696
endfunction()
697697

698+
# ##############################################################################
699+
function(hpx_check_for_cxx23_std_unordered_transparent_erase)
700+
add_hpx_config_test(
701+
HPX_WITH_CXX23_STD_UNORDERED_TRANSPARENT_ERASE
702+
SOURCE cmake/tests/cxx23_std_unordered_transparent_erase.cpp
703+
FILE ${ARGN}
704+
)
705+
endfunction()
706+
707+
# ##############################################################################
708+
function(hpx_check_for_cxx26_std_unordered_transparent_lookup)
709+
add_hpx_config_test(
710+
HPX_WITH_CXX26_STD_UNORDERED_TRANSPARENT_LOOKUP
711+
SOURCE cmake/tests/cxx26_std_unordered_transparent_lookup.cpp
712+
FILE ${ARGN}
713+
)
714+
endfunction()
715+
698716
# ##############################################################################
699717
function(hpx_check_for_stable_inplace_merge)
700718
add_hpx_config_test(

cmake/HPX_PerformCxxFeatureTests.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ function(hpx_perform_cxx_feature_tests)
171171
DEFINITIONS HPX_HAVE_CXX_LAMBDA_CAPTURE_DECLTYPE
172172
)
173173

174+
hpx_check_for_cxx23_std_unordered_transparent_erase(
175+
DEFINITIONS HPX_HAVE_CXX23_STD_UNORDERED_TRANSPARENT_ERASE
176+
)
177+
178+
hpx_check_for_cxx26_std_unordered_transparent_lookup(
179+
DEFINITIONS HPX_HAVE_CXX26_STD_UNORDERED_TRANSPARENT_LOOKUP
180+
)
181+
174182
hpx_check_for_builtin_forward_move(DEFINITIONS HPX_HAVE_BUILTIN_FORWARD_MOVE)
175183

176184
hpx_check_for_builtin_frame_address(
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2026 Pratyksh Gupta
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <cstddef>
8+
#include <string>
9+
#include <string_view>
10+
#include <unordered_map>
11+
12+
struct transparent_hash
13+
{
14+
using is_transparent = void;
15+
std::size_t operator()(std::string_view sv) const
16+
{
17+
return std::hash<std::string_view>{}(sv);
18+
}
19+
std::size_t operator()(std::string const& s) const
20+
{
21+
return std::hash<std::string>{}(s);
22+
}
23+
};
24+
25+
struct transparent_equal
26+
{
27+
using is_transparent = void;
28+
bool operator()(std::string_view sv, std::string const& s) const
29+
{
30+
return sv == s;
31+
}
32+
bool operator()(std::string const& s, std::string_view sv) const
33+
{
34+
return s == sv;
35+
}
36+
bool operator()(std::string const& s1, std::string const& s2) const
37+
{
38+
return s1 == s2;
39+
}
40+
};
41+
42+
int main()
43+
{
44+
std::unordered_map<std::string, int, transparent_hash, transparent_equal> m;
45+
m["hello"] = 1;
46+
47+
// Test erase with transparent key (C++23)
48+
m.erase(std::string_view("hello"));
49+
50+
if (!m.empty())
51+
return 1;
52+
53+
return 0;
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2026 Pratyksh Gupta
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <cstddef>
8+
#include <string>
9+
#include <string_view>
10+
#include <unordered_map>
11+
12+
struct transparent_hash
13+
{
14+
using is_transparent = void;
15+
std::size_t operator()(std::string_view sv) const
16+
{
17+
return std::hash<std::string_view>{}(sv);
18+
}
19+
std::size_t operator()(std::string const& s) const
20+
{
21+
return std::hash<std::string>{}(s);
22+
}
23+
};
24+
25+
struct transparent_equal
26+
{
27+
using is_transparent = void;
28+
bool operator()(std::string_view sv, std::string const& s) const
29+
{
30+
return sv == s;
31+
}
32+
bool operator()(std::string const& s, std::string_view sv) const
33+
{
34+
return s == sv;
35+
}
36+
bool operator()(std::string const& s1, std::string const& s2) const
37+
{
38+
return s1 == s2;
39+
}
40+
};
41+
42+
int main()
43+
{
44+
std::unordered_map<std::string, int, transparent_hash, transparent_equal> m;
45+
m["hello"] = 1;
46+
47+
// Test operator[] with transparent key (C++26)
48+
m[std::string_view("hello")] = 42;
49+
50+
// Test at() with transparent key (C++26)
51+
if (m.at(std::string_view("hello")) != 42)
52+
return 1;
53+
54+
return 0;
55+
}

libs/core/concurrency/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1010
set(concurrency_headers
1111
hpx/concurrency/barrier.hpp
1212
hpx/concurrency/cache_line_data.hpp
13+
hpx/concurrency/concurrent_queue.hpp
14+
hpx/concurrency/concurrent_unordered_map.hpp
15+
hpx/concurrency/concurrent_unordered_set.hpp
16+
hpx/concurrency/concurrent_vector.hpp
1317
hpx/concurrency/concurrentqueue.hpp
1418
hpx/concurrency/deque.hpp
19+
hpx/concurrency/detail/concurrent_accessor.hpp
1520
hpx/concurrency/detail/contiguous_index_queue.hpp
1621
hpx/concurrency/detail/copy_payload.hpp
1722
hpx/concurrency/detail/freelist.hpp
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2026 Pratyksh Gupta
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#pragma once
8+
9+
#include <hpx/config.hpp>
10+
#include <hpx/concurrency/queue.hpp>
11+
12+
#include <memory>
13+
14+
namespace hpx::concurrent {
15+
16+
template <typename T, typename Allocator = std::allocator<T>>
17+
using concurrent_queue = hpx::lockfree::queue<T, Allocator>;
18+
19+
} // namespace hpx::concurrent

0 commit comments

Comments
 (0)