Polymorphic Map and threadpool

This commit is contained in:
2021-11-01 20:25:16 +01:00
parent 9c48c48f8c
commit 1b7ab9b1f1
20 changed files with 1442 additions and 1280 deletions
+24 -7
View File
@@ -1,6 +1,6 @@
#pragma once
#include "MinimalEngine.h"
#include <xmemory>
#include <memory_resource>
namespace Seele
{
@@ -187,11 +187,11 @@ public:
return *this;
}
T &front()
reference front()
{
return root->data;
}
T &back()
reference back()
{
return tail->prev->data;
}
@@ -218,7 +218,7 @@ public:
root = allocateNode();
tail = root;
}
tail->data = value;
initializeNode(tail, value);
Node *newTail = allocateNode();
newTail->prev = tail;
newTail->next = nullptr;
@@ -236,7 +236,7 @@ public:
root = allocateNode();
tail = root;
}
tail->data = std::move(value);
initializeNode(tail, std::move(value));
Node *newTail = allocateNode();
newTail->prev = tail;
newTail->next = nullptr;
@@ -247,6 +247,13 @@ public:
_size++;
return insertedElement;
}
// front + popFront
value_type&& retrieve()
{
auto&& temp = std::move(root->data);
popFront();
return std::move(temp);
}
iterator remove(iterator pos)
{
_size--;
@@ -299,7 +306,7 @@ public:
}
Node *tmp = pos.node->prev;
Node *newNode = allocateNode();
newNode->data = value;
initializeNode(newNode, value);
tmp->next = newNode;
newNode->prev = tmp;
newNode->next = pos.node;
@@ -346,10 +353,20 @@ private:
Node* allocateNode()
{
Node* node = allocator.allocate(1);
std::memset(node, 0, sizeof(Node));
assert(node != nullptr);
node->prev = nullptr;
node->next = nullptr;
return node;
}
template<typename Type>
void initializeNode(Node* node, Type&& data)
{
std::allocator_traits<NodeAllocator>::construct(allocator,
node,
node->prev,
node->next,
std::forward<Type>(data));
}
void deallocateNode(Node* node)
{
allocator.deallocate(node, 1);