3#include "IntrusiveList.h"
12 for(
auto * item : *list) {
23Cogs::IntrusiveList::IntrusiveList()
25 head = (IntrusiveNode*)&tail;
27 tailPrev = (IntrusiveNode*)&head;
29 assert(count(
this) == 0);
32bool Cogs::IntrusiveList::empty()
const
34 return tailPrev == (IntrusiveNode*)&head;
37void Cogs::IntrusiveList::pushFront(IntrusiveNode* node)
39 assert(node->next ==
nullptr);
40 assert(node->prev ==
nullptr);
45 node->prev = (IntrusiveNode*)&head;
52 assert(head->prev !=
nullptr);
53 assert(tailPrev != (IntrusiveNode*)&head);
56void Cogs::IntrusiveList::pushBack(IntrusiveNode* node)
58 assert(node->next ==
nullptr);
59 assert(node->prev ==
nullptr);
63 node->next = (IntrusiveNode*)&tail;
64 node->prev = tailPrev;
65 tailPrev->next = node;
71 assert(head->prev !=
nullptr);
72 assert(tailPrev != (IntrusiveNode*)&head);
75void Cogs::IntrusiveList::insert(IntrusiveNode* prev, IntrusiveNode* node)
79 assert(node->next ==
nullptr);
80 assert(node->prev ==
nullptr);
81 assert(head->prev !=
nullptr &&
"List is empty");
82 assert(tailPrev != (IntrusiveNode*)&head &&
"List is empty");
87 node->next = prev->next;
89 prev->next->prev = node;
93 node->next = (IntrusiveNode*)&tail;
94 node->prev = tailPrev;
95 tailPrev->next = node;
102 assert(head->prev !=
nullptr);
103 assert(tailPrev != (IntrusiveNode*)&head);
108 IntrusiveNode* node = head->next;
111 auto n = count(
this);
113 node->prev = (IntrusiveNode*)&head;
117 node->next =
nullptr;
118 node->prev =
nullptr;
120 auto m = count(
this);
128 if (tailPrev != (IntrusiveNode*)&head) {
136void Cogs::IntrusiveList::remove(IntrusiveNode* node)
140 auto n = count(
this);
142 node->prev->next = node->next;
143 node->next->prev = node->prev;
144 node->next =
nullptr;
145 node->prev =
nullptr;
147 auto m = count(
this);
153 IntrusiveNode* node = back();