From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 26 Jul 2018 01:55:47 +0000 (+0900) Subject: [coco] Support 'prepend' operation (#822) X-Git-Tag: nncc_backup~2301 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2fdde2e679b2138d70921f192a0c364be9510cbf;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Support 'prepend' operation (#822) This commit implements 'prepend' operation in 'DLinkedList' trait. Now, users are able to insert Child element at the head of a list. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/ADT/DLinkedList.h b/contrib/coco/core/include/coco/ADT/DLinkedList.h index f29951f..20b8d3a 100644 --- a/contrib/coco/core/include/coco/ADT/DLinkedList.h +++ b/contrib/coco/core/include/coco/ADT/DLinkedList.h @@ -75,6 +75,19 @@ template struct DLinkedList } public: + void prepend(Child *child) + { + if (empty()) + { + enlist(child); + } + else + { + child->insertBefore(_head); + } + } + + public: void append(Child *child) { if (empty()) diff --git a/contrib/coco/core/src/ADT/DLinkedList.test.cpp b/contrib/coco/core/src/ADT/DLinkedList.test.cpp index 8138cce..0883838 100644 --- a/contrib/coco/core/src/ADT/DLinkedList.test.cpp +++ b/contrib/coco/core/src/ADT/DLinkedList.test.cpp @@ -114,3 +114,29 @@ TEST(ADT_DLINKED_LINK, insertBefore) delete parent; delete link; } + +TEST(ADT_DLINKED_LINK, prepend_after_append) +{ + auto link = new coco::PtrLink<::Child, ::Parent>{}; + auto parent = new ::Parent{link}; + + auto child_1 = new ::Child{link}; + auto child_2 = new ::Child{link}; + + parent->children()->append(child_1); + parent->children()->prepend(child_2); + + ASSERT_EQ(child_2->next(), child_1); + + ASSERT_EQ(child_1->parent(), parent); + ASSERT_EQ(child_1->prev(), child_2); + ASSERT_EQ(child_1->next(), nullptr); + + ASSERT_EQ(parent->children()->head(), child_2); + ASSERT_EQ(parent->children()->tail(), child_1); + + delete child_2; + delete child_1; + delete parent; + delete link; +}