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 IntrusiveSingleList(
const IntrusiveSingleList &) =
delete;
39 IntrusiveSingleList &operator=(
const IntrusiveSingleList &) =
delete;
42 void push_back(T *item)
noexcept {
43 assert(item !=
nullptr);
44 SingleLinkEntry *entry = &(item->*Member);
45 assert(entry->next ==
nullptr);
46 entry->next =
nullptr;
56 void push_back(IntrusiveSingleList other)
noexcept {
64 tail_->next = other.head_;
69 bool empty() const noexcept {
return head_ ==
nullptr; }
71 T *pop_front() noexcept {
75 SingleLinkEntry *entry = head_;
80 entry->next =
nullptr;
81 return container_of(Member, entry);
85 SingleLinkEntry *head_ =
nullptr;
86 SingleLinkEntry *tail_ =
nullptr;
89template <
typename T, DoubleLinkEntry T::*Member>
class IntrusiveDoubleList {
91 IntrusiveDoubleList() =
default;
92 IntrusiveDoubleList(IntrusiveDoubleList &&other) noexcept
93 : head_(std::exchange(other.head_,
nullptr)),
94 tail_(std::exchange(other.tail_,
nullptr)) {}
95 IntrusiveDoubleList &operator=(IntrusiveDoubleList &&other)
noexcept {
98 head_ = std::exchange(other.head_,
nullptr);
99 tail_ = std::exchange(other.tail_,
nullptr);
104 IntrusiveDoubleList(
const IntrusiveDoubleList &) =
delete;
105 IntrusiveDoubleList &operator=(
const IntrusiveDoubleList &) =
delete;
108 void push_back(T *item)
noexcept {
109 assert(item !=
nullptr);
110 DoubleLinkEntry *entry = &(item->*Member);
111 assert(entry->next ==
nullptr && entry->prev ==
nullptr);
112 entry->next =
nullptr;
123 bool empty() const noexcept {
return head_ ==
nullptr; }
125 T *pop_front() noexcept {
129 DoubleLinkEntry *entry = head_;
132 head_->prev =
nullptr;
136 entry->next =
nullptr;
137 entry->prev =
nullptr;
138 return container_of(Member, entry);
141 bool remove(T *item)
noexcept {
142 assert(item !=
nullptr);
143 DoubleLinkEntry *entry = &(item->*Member);
144 if (entry->prev ==
nullptr && entry->next ==
nullptr &&
149 entry->prev->next = entry->next;
151 assert(head_ == entry);
155 entry->next->prev = entry->prev;
157 assert(tail_ == entry);
160 entry->next =
nullptr;
161 entry->prev =
nullptr;
166 DoubleLinkEntry *head_ =
nullptr;
167 DoubleLinkEntry *tail_ =
nullptr;
The main namespace for the Condy library.
Internal utility classes and functions used by Condy.