From 432238635b7f25268adffd4f8f5252646ebcca04 Mon Sep 17 00:00:00 2001 From: 12hydrogen Date: Thu, 25 Jun 2026 15:07:55 +0800 Subject: [PATCH] make archives for current stage --- CMakeLists.txt | 5 +++++ pool.cpp | 8 ++++++++ pool.hpp | 38 +++++++++++++++++++++++++++++--------- shift.cpp | 21 +++++++++++++++++++++ 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 shift.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fd49c6d..66e6b2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,3 +31,8 @@ target_link_libraries( test_server PUBLIC wrapper ) + +add_executable( + test_shift + ./shift.cpp +) diff --git a/pool.cpp b/pool.cpp index e69de29..918a31b 100644 --- a/pool.cpp +++ b/pool.cpp @@ -0,0 +1,8 @@ +#include "pool.hpp" + +int main() { + Queue queue; + + queue.push(1); + auto load = queue.pop(); +} diff --git a/pool.hpp b/pool.hpp index 7047d79..cace14d 100644 --- a/pool.hpp +++ b/pool.hpp @@ -7,18 +7,38 @@ #include -#include -#include - +#include template -struct Message { +struct QNode { std::unique_ptr payload; + volatile std::atomic next; + + QNode() = default; + + explicit QNode(T&& payload): + payload(std::forward(payload)) {} }; template -struct Queue { - std::forward_list> queue; -}; +class Queue { +private: + volatile std::atomic*> head; + volatile std::atomic*> tail; +public: + void push(T&& payload) { + QNode* node = new QNode(std::forward(payload)); + node->next = node; -template -struct Tunnel {}; + QNode* _tail = tail; + QNode* _next = _tail->next; + + do { + node->next = _next; + } while (!_tail->next.compare_exchange_weak(_next, node)); + + tail.compare_exchange_strong(_tail, node); + } + std::unique_ptr pop() { + + } +}; diff --git a/shift.cpp b/shift.cpp new file mode 100644 index 0000000..b232b41 --- /dev/null +++ b/shift.cpp @@ -0,0 +1,21 @@ +#include +#include + +template +void shifting(vector &list, int k) { + for (int i = 0; (i + 1) * k < list.size(); ++ i) { + for (int j = 0; j < k; ++ j) { + std::swap(list[i * k + j], list[(i + 1) * k + j]); + } + } + int m = n % k; + for (int i = 0; i < m; ++ i) { + for (int j = 0; j < k; ++ j) { + std::swap(list[n - k], list[n - k - 1]); + } + } +} + +int main() { + return 0; +}