added cpp

This commit is contained in:
g2px1 2025-05-01 12:47:29 +03:00
parent beb1bfa234
commit 63aaf9a3de
4 changed files with 15 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea
cmake-build-debug

View File

@ -5,4 +5,5 @@ set(CMAKE_CXX_STANDARD 20)
add_executable(parallelUnorderedMap main.cpp
UnorderedParallelMap.h
optimization.h)
optimization.h
UnorderedParallelMap.cpp)

5
UnorderedParallelMap.cpp Normal file
View File

@ -0,0 +1,5 @@
//
// Created by Kirill Zhukov on 01.05.2025.
//
#include "UnorderedParallelMap.h"

View File

@ -11,6 +11,7 @@
template <typename K, typename V>
class LockFreeMap
{
private:
struct Bucket
{
std::atomic<bool> occupied{false};
@ -25,7 +26,9 @@ class LockFreeMap
size_t capacity;
std::vector<Bucket> buckets;
Table(size_t cap) : capacity(cap), buckets(cap) {}
explicit Table(size_t cap) : capacity(cap), buckets(cap)
{
}
};
std::shared_ptr<Table> table;
@ -94,7 +97,8 @@ class LockFreeMap
auto next = std::make_shared<Table>(new_capacity);
new_table = next;
std::thread([this, old_table, next]() {
std::thread([this, old_table, next]()
{
for (auto& bucket : old_table->buckets)
{
Bucket* current = &bucket;
@ -357,7 +361,6 @@ public:
}
}
}
};
#endif // UNORDEREDPARALLELMAP_H