ONE - On-device Neural Engine
Loading...
Searching...
No Matches
coco::DLinkedList< Child, Parent >::Node Class Reference

#include <DLinkedList.h>

Public Member Functions

 Node ()
 
virtual ~Node ()
 
Parent * parent (void) const
 
Child * prev (void) const
 
Child * next (void) const
 
void insertBefore (Node *next)
 
void insertAfter (Node *prev)
 
void detach (void)
 

Friends

class Head
 

Detailed Description

template<typename Child, typename Parent>
class coco::DLinkedList< Child, Parent >::Node

Definition at line 160 of file DLinkedList.h.

Constructor & Destructor Documentation

◆ Node()

template<typename Child , typename Parent >
coco::DLinkedList< Child, Parent >::Node::Node ( )
inline

Definition at line 166 of file DLinkedList.h.

167 {
168 static_assert(std::is_base_of<Node, Child>::value,
169 "Type `Child` must be subclass of `Node`.");
170
171 _prev = nullptr;
172 _next = nullptr;
173 }

◆ ~Node()

template<typename Child , typename Parent >
virtual coco::DLinkedList< Child, Parent >::Node::~Node ( )
inlinevirtual

Definition at line 176 of file DLinkedList.h.

177 {
178 // Each Child should unlink itself on destruction
179 //
180 // NOTE detach invokes "leaving" hook which may access the internal of each Child,
181 // so it is not safe to invoke detach here
182 assert(parent() == nullptr);
183 }
Parent * parent(void) const

References coco::DLinkedList< Child, Parent >::Node::parent().

Member Function Documentation

◆ detach()

template<typename Child , typename Parent >
void coco::DLinkedList< Child, Parent >::Node::detach ( void  )
inline

Definition at line 250 of file DLinkedList.h.

251 {
252 // Update parent-child relation
253 assert(parent() != nullptr);
254 assert(head(parent()) != nullptr);
255 head(parent())->delist(curr());
256 assert(parent() == nullptr);
257
258 // Update the link of sibling nodes
259 if (prev())
260 {
261 prev()->_next = next();
262 }
263
264 if (next())
265 {
266 next()->_prev = prev();
267 }
268
269 // Update the link of the current node
270 _prev = nullptr;
271 _next = nullptr;
272 }
void delist(Child *child)
Child * next(void) const
Child * prev(void) const
static Head * head(Parent *)

References coco::DLinkedList< Child, Parent >::Head::delist(), coco::DLinkedList< Child, Parent >::head(), coco::DLinkedList< Child, Parent >::Node::next(), coco::DLinkedList< Child, Parent >::Node::parent(), and coco::DLinkedList< Child, Parent >::Node::prev().

Referenced by coco::Block::~Block(), and coco::Instr::~Instr().

◆ insertAfter()

template<typename Child , typename Parent >
void coco::DLinkedList< Child, Parent >::Node::insertAfter ( Node prev)
inline

Definition at line 223 of file DLinkedList.h.

224 {
225 assert(prev != nullptr);
226 assert(prev->parent() != nullptr);
227 assert(head(prev->parent()) != nullptr);
228
229 assert(_prev == nullptr);
230 assert(_next == nullptr);
231
232 // Update the link of the current node
233 _prev = prev->curr();
234 _next = prev->next();
235
236 // Update the link of the sibling nodes
237 if (auto next = prev->next())
238 {
239 next->_prev = curr();
240 }
241 prev->_next = curr();
242
243 // Update parent-child relation
244 assert(parent() == nullptr);
245 head(prev->parent())->enlist(curr());
246 assert(parent() == prev->parent());
247 };
void enlist(Child *child)
Definition DLinkedList.h:66

References coco::DLinkedList< Child, Parent >::Head::enlist(), coco::DLinkedList< Child, Parent >::head(), coco::DLinkedList< Child, Parent >::Node::next(), coco::DLinkedList< Child, Parent >::Node::parent(), and coco::DLinkedList< Child, Parent >::Node::prev().

◆ insertBefore()

template<typename Child , typename Parent >
void coco::DLinkedList< Child, Parent >::Node::insertBefore ( Node next)
inline

Definition at line 197 of file DLinkedList.h.

198 {
199 assert(next != nullptr);
200 assert(next->parent() != nullptr);
201 assert(head(next->parent()) != nullptr);
202
203 assert(_prev == nullptr);
204 assert(_next == nullptr);
205
206 // Update the link of the current node
207 _prev = next->prev();
208 _next = next->curr();
209
210 if (auto prev = next->prev())
211 {
212 prev->_next = curr();
213 }
214 next->_prev = curr();
215
216 // Update parent-child relation
217 assert(parent() == nullptr);
218 head(next->parent())->enlist(curr());
219 assert(parent() == next->parent());
220 }

References coco::DLinkedList< Child, Parent >::Head::enlist(), coco::DLinkedList< Child, Parent >::head(), coco::DLinkedList< Child, Parent >::Node::next(), coco::DLinkedList< Child, Parent >::Node::parent(), and coco::DLinkedList< Child, Parent >::Node::prev().

◆ next()

◆ parent()

◆ prev()

Friends And Related Symbol Documentation

◆ Head

template<typename Child , typename Parent >
friend class Head
friend

Definition at line 163 of file DLinkedList.h.


The documentation for this class was generated from the following file: