make archives for current stage
This commit is contained in:
@@ -31,3 +31,8 @@ target_link_libraries(
|
|||||||
test_server
|
test_server
|
||||||
PUBLIC wrapper
|
PUBLIC wrapper
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(
|
||||||
|
test_shift
|
||||||
|
./shift.cpp
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "pool.hpp"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Queue<int> queue;
|
||||||
|
|
||||||
|
queue.push(1);
|
||||||
|
auto load = queue.pop();
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,18 +7,38 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <vector>
|
#include <type_traits>
|
||||||
#include <forward_list>
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Message {
|
struct QNode {
|
||||||
std::unique_ptr<T> payload;
|
std::unique_ptr<T> payload;
|
||||||
|
volatile std::atomic<QNode*> next;
|
||||||
|
|
||||||
|
QNode() = default;
|
||||||
|
|
||||||
|
explicit QNode(T&& payload):
|
||||||
|
payload(std::forward<T>(payload)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Queue {
|
class Queue {
|
||||||
std::forward_list<Message<T>> queue;
|
private:
|
||||||
};
|
volatile std::atomic<QNode<T>*> head;
|
||||||
|
volatile std::atomic<QNode<T>*> tail;
|
||||||
|
public:
|
||||||
|
void push(T&& payload) {
|
||||||
|
QNode<T>* node = new QNode(std::forward<T>(payload));
|
||||||
|
node->next = node;
|
||||||
|
|
||||||
template <typename T>
|
QNode<T>* _tail = tail;
|
||||||
struct Tunnel {};
|
QNode<T>* _next = _tail->next;
|
||||||
|
|
||||||
|
do {
|
||||||
|
node->next = _next;
|
||||||
|
} while (!_tail->next.compare_exchange_weak(_next, node));
|
||||||
|
|
||||||
|
tail.compare_exchange_strong(_tail, node);
|
||||||
|
}
|
||||||
|
std::unique_ptr<T> pop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void shifting(vector<T> &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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user