From fb6d06d459e34b3f37a9fd5d7c9e4df6e63a9fdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 14 Sep 2018 16:48:31 +0900 Subject: [PATCH] [coco] Direct Parent-Child relation update in DLinkedList (#1491) This commit revises DLinkedLists to directly updates parent-child relations instead of using PtrLink. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/ADT/DLinkedList.h | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/contrib/coco/core/include/coco/ADT/DLinkedList.h b/contrib/coco/core/include/coco/ADT/DLinkedList.h index 4bfd804..81ac344 100644 --- a/contrib/coco/core/include/coco/ADT/DLinkedList.h +++ b/contrib/coco/core/include/coco/ADT/DLinkedList.h @@ -15,7 +15,8 @@ template struct DLinkedList class Head { public: - Head(Parent *parent, PtrLink *link) : _parent{parent}, _link{link} + // TODO _link is no longer used + Head(Parent *parent, PtrLink *link) : _parent{parent} { _head = nullptr; _tail = nullptr; @@ -72,7 +73,7 @@ template struct DLinkedList } // Update parent-child relation - _link->set(child, _parent); + child->parent(_parent); } public: @@ -92,7 +93,7 @@ template struct DLinkedList } // Update parent-child relation - _link->unset(child); + child->parent(nullptr); } public: @@ -123,7 +124,6 @@ template struct DLinkedList private: Parent *const _parent; - PtrLink *const _link; private: Child *_head; @@ -133,6 +133,9 @@ template struct DLinkedList class Node { public: + friend class Head; + + public: Node() { static_assert(std::is_base_of::value, @@ -146,16 +149,11 @@ template struct DLinkedList virtual ~Node() = default; protected: + // NOTE This method will be deprecated virtual void get(const PtrLink **out) const = 0; public: - Parent *parent(void) const - { - const PtrLink *link = nullptr; - get(&link); - assert(link != nullptr); - return link->find(curr()); - } + Parent *parent(void) const { return _parent; } private: Child *curr(void) { return reinterpret_cast(this); } @@ -245,6 +243,12 @@ template struct DLinkedList } private: + // WARN Do NOT invoke this method outside Head::enlist + void parent(Parent *p) { _parent = p; } + + private: + // WARN Do NOT modify this field inside Node. + Parent *_parent = nullptr; Child *_prev; Child *_next; }; -- 2.7.4