added cpp
This commit is contained in:
parent
beb1bfa234
commit
63aaf9a3de
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea
|
||||
cmake-build-debug
|
@ -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
5
UnorderedParallelMap.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by Kirill Zhukov on 01.05.2025.
|
||||
//
|
||||
|
||||
#include "UnorderedParallelMap.h"
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user