diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b1aab2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +cmake-build-debug \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e99fbaf..4560046 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,5 @@ set(CMAKE_CXX_STANDARD 20) add_executable(parallelUnorderedMap main.cpp UnorderedParallelMap.h - optimization.h) + optimization.h + UnorderedParallelMap.cpp) diff --git a/UnorderedParallelMap.cpp b/UnorderedParallelMap.cpp new file mode 100644 index 0000000..5afe7f0 --- /dev/null +++ b/UnorderedParallelMap.cpp @@ -0,0 +1,5 @@ +// +// Created by Kirill Zhukov on 01.05.2025. +// + +#include "UnorderedParallelMap.h" \ No newline at end of file diff --git a/UnorderedParallelMap.h b/UnorderedParallelMap.h index d412533..1bb6304 100644 --- a/UnorderedParallelMap.h +++ b/UnorderedParallelMap.h @@ -11,6 +11,7 @@ template class LockFreeMap { +private: struct Bucket { std::atomic occupied{false}; @@ -25,7 +26,9 @@ class LockFreeMap size_t capacity; std::vector buckets; - Table(size_t cap) : capacity(cap), buckets(cap) {} + explicit Table(size_t cap) : capacity(cap), buckets(cap) + { + } }; std::shared_ptr table; @@ -94,7 +97,8 @@ class LockFreeMap auto next = std::make_shared
(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