14struct SingleLinkEntry {
15 SingleLinkEntry *next =
nullptr;
18struct DoubleLinkEntry {
19 DoubleLinkEntry *next =
nullptr;
20 DoubleLinkEntry *prev =
nullptr;
23template <
typename T, SingleLinkEntry T::*Member>
class IntrusiveSingleList {
25 IntrusiveSingleList() =
default;
26 IntrusiveSingleList(IntrusiveSingleList &&other) noexcept
27 : head_(std::exchange(other.head_,
nullptr)),
28 tail_(std::exchange(other.tail_,
nullptr)) {}
29 IntrusiveSingleList &operator=(IntrusiveSingleList &&other)
noexcept {
32 head_ = std::exchange(other.head_,
nullptr);
33 tail_ = std::exchange(other.tail_,
nullptr);
38 CONDY_DELETE_COPY(IntrusiveSingleList);
41 void push_back(T *item)
noexcept {
42 assert(item !=
nullptr);
43 SingleLinkEntry *entry = &(item->*Member);
44 assert(entry->next ==
nullptr);
45 entry->next =
nullptr;
55 void push_back(IntrusiveSingleList other)
noexcept {
63 tail_->next = other.head_;
68 bool empty() const noexcept {
return head_ ==
nullptr; }
70 T *pop_front() noexcept {
74 SingleLinkEntry *entry = head_;
79 entry->next =
nullptr;
80 return container_of(Member, entry);
84 SingleLinkEntry *head_ =
nullptr;
85 SingleLinkEntry *tail_ =
nullptr;
88template <
typename T, DoubleLinkEntry T::*Member>
class IntrusiveDoubleList {
90 IntrusiveDoubleList() =
default;
91 IntrusiveDoubleList(IntrusiveDoubleList &&other) noexcept
92 : head_(std::exchange(other.head_,
nullptr)),
93 tail_(std::exchange(other.tail_,
nullptr)) {}
94 IntrusiveDoubleList &operator=(IntrusiveDoubleList &&other)
noexcept {
97 head_ = std::exchange(other.head_,
nullptr);
98 tail_ = std::exchange(other.tail_,
nullptr);
103 CONDY_DELETE_COPY(IntrusiveDoubleList);
106 void push_back(T *item)
noexcept {
107 assert(item !=
nullptr);
108 DoubleLinkEntry *entry = &(item->*Member);
109 assert(entry->next ==
nullptr && entry->prev ==
nullptr);
110 entry->next =
nullptr;
121 bool empty() const noexcept {
return head_ ==
nullptr; }
123 T *pop_front() noexcept {
127 DoubleLinkEntry *entry = head_;
130 head_->prev =
nullptr;
134 entry->next =
nullptr;
135 entry->prev =
nullptr;
136 return container_of(Member, entry);
139 bool remove(T *item)
noexcept {
140 assert(item !=
nullptr);
141 DoubleLinkEntry *entry = &(item->*Member);
142 if (entry->prev ==
nullptr && entry->next ==
nullptr &&
147 entry->prev->next = entry->next;
149 assert(head_ == entry);
153 entry->next->prev = entry->prev;
155 assert(tail_ == entry);
158 entry->next =
nullptr;
159 entry->prev =
nullptr;
164 DoubleLinkEntry *head_ =
nullptr;
165 DoubleLinkEntry *tail_ =
nullptr;
The main namespace for the Condy library.
Internal utility classes and functions used by Condy.