YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
intrusive_list.cpp
Go to the documentation of this file.
1#include <yaclib/log.hpp>
3
4#include <utility>
5
6namespace yaclib::detail {
7
8List::List(List&& other) noexcept {
9 if (this == &other || other.Empty()) {
10 return; // TODO(MBkkt) Remove if
11 }
12 _head.next = std::exchange(other._head.next, nullptr);
13 _tail = std::exchange(other._tail, &other._head);
14}
15
16void List::PushFront(Node& node) noexcept {
17 if (Empty()) {
18 _tail = &node;
19 }
20 node.next = _head.next;
21 _head.next = &node;
22}
23
24void List::PushBack(Node& node) noexcept {
25 // for circular should be node.next = _tail->next;
26 node.next = nullptr;
27 _tail->next = &node;
28 _tail = &node;
29}
30
32 YACLIB_DEBUG((_head.next == nullptr) != (_tail == &_head), "List::Empty invariant is failed");
33 return _head.next == nullptr; // valid only for linear
34}
35
38 auto* node = _head.next;
39 _head.next = node->next;
40 if (_head.next == nullptr) {
41 _tail = &_head;
42 }
43 return *node;
44}
45
46} // namespace yaclib::detail
bool Empty() const noexcept
Node & PopFront() noexcept
List() noexcept=default
void PushFront(Node &node) noexcept
void PushBack(Node &node) noexcept
#define YACLIB_DEBUG(cond, message)
Definition log.hpp:84
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
Node class, used in intrusive data structure.
Definition node.hpp:8