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
|
add_executable(parallelUnorderedMap main.cpp
|
||||||
UnorderedParallelMap.h
|
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>
|
template <typename K, typename V>
|
||||||
class LockFreeMap
|
class LockFreeMap
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
struct Bucket
|
struct Bucket
|
||||||
{
|
{
|
||||||
std::atomic<bool> occupied{false};
|
std::atomic<bool> occupied{false};
|
||||||
@ -25,7 +26,9 @@ class LockFreeMap
|
|||||||
size_t capacity;
|
size_t capacity;
|
||||||
std::vector<Bucket> buckets;
|
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;
|
std::shared_ptr<Table> table;
|
||||||
@ -94,7 +97,8 @@ class LockFreeMap
|
|||||||
auto next = std::make_shared<Table>(new_capacity);
|
auto next = std::make_shared<Table>(new_capacity);
|
||||||
new_table = next;
|
new_table = next;
|
||||||
|
|
||||||
std::thread([this, old_table, next]() {
|
std::thread([this, old_table, next]()
|
||||||
|
{
|
||||||
for (auto& bucket : old_table->buckets)
|
for (auto& bucket : old_table->buckets)
|
||||||
{
|
{
|
||||||
Bucket* current = &bucket;
|
Bucket* current = &bucket;
|
||||||
@ -357,7 +361,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UNORDEREDPARALLELMAP_H
|
#endif // UNORDEREDPARALLELMAP_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user