5#ifndef RUNTIME_VM_INTRUSIVE_DLIST_H_
6#define RUNTIME_VM_INTRUSIVE_DLIST_H_
54template <
typename T,
int N>
57template <
typename T,
int N = 1>
64 ASSERT((next_ ==
nullptr && prev_ ==
nullptr) ||
65 (next_ ==
this && prev_ ==
this));
70 ASSERT(next_ ==
nullptr && prev_ ==
nullptr);
81 T* container() {
return static_cast<T*
>(
this); }
83 void Append(IntrusiveDListEntry<T, N>* entry) {
84 ASSERT(entry->next_ ==
nullptr && entry->prev_ ==
nullptr);
88 entry->next_->prev_ = entry;
91 void Prepend(IntrusiveDListEntry<T, N>* entry) {
92 ASSERT(entry->next_ ==
nullptr && entry->prev_ ==
nullptr);
96 entry->prev_->next_ = entry;
100 ASSERT(prev_->next_ ==
this);
101 ASSERT(next_->prev_ ==
this);
102 ASSERT(prev_ !=
this && next_ !=
this);
104 prev_->next_ = next_;
105 next_->prev_ = prev_;
111 bool IsEmpty()
const {
112 bool result = next_ ==
this;
117 bool IsLinked()
const {
118 ASSERT((next_ ==
nullptr) == (prev_ ==
nullptr));
119 return next_ !=
nullptr;
122 IntrusiveDListEntry<T, N>* Prev()
const {
return prev_; }
134template <
typename T,
int N = 1>
139 template <
typename ContainerType,
int I = 1>
144 : head_(
head), entry_(entry) {}
146 inline ContainerType*
operator->()
const {
return entry_->container(); }
148 inline ContainerType*
operator*()
const {
return entry_->container(); }
151 return entry_ == other.entry_;
155 return !(*
this == other);
159 entry_ = entry_->Next();
164 entry_ = entry_->Prev();
183 inline bool IsInList(
T*
a)
const {
return convert(
a)->IsLinked(); }
187 inline bool IsEmpty()
const {
return head_.IsEmpty(); }
191 return head_.Next()->container();
196 return head_.Prev()->container();
201 auto entry = head_.Next();
202 T* container = entry->container();
209 auto entry = head_.Prev();
210 T* container = entry->container();
224 ASSERT(iterator.head_ ==
this);
226 iterator.entry_->Remove();
231 for (
auto entry : *
this) {
232 if (entry ==
a)
return true;
240 auto other_first = other->head_.Next();
241 auto other_last = other->head_.Prev();
242 other->head_.next_ = &other->head_;
243 other->head_.prev_ = &other->head_;
245 auto prev = head_.prev_;
247 prev->next_ = other_first;
248 other_first->prev_ =
prev;
250 other_last->next_ = &head_;
251 head_.prev_ = other_last;
257 Entry* convert(
T* entry)
const {
return static_cast<Entry*
>(entry); }
static float next(float f)
static float prev(float f)
ContainerType * operator->() const
bool operator==(const Iterator< ContainerType, I > &other) const
ContainerType * operator*() const
bool operator!=(const Iterator< ContainerType, I > &other) const
Iterator(IntrusiveDList< ContainerType, I > *head, IntrusiveDListEntry< ContainerType, I > *entry)
Iterator< ContainerType, I > & operator--()
Iterator< ContainerType, I > & operator++()
void AppendList(IntrusiveDList< T, N > *other)
Iterator< T, N > Erase(const Iterator< T, N > &iterator)
IntrusiveDListEntry< T, N > Entry
bool IsInList(T *a) const
bool ContainsForDebugging(const T *a)