[coco] Introduce Shuffle::size method (#1539)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 18 Sep 2018 09:42:29 +0000 (18:42 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 18 Sep 2018 09:42:29 +0000 (18:42 +0900)
* [coco] Introduce Shuffle::size method

This commit introduces Shuffle::size method which allows us to get the
number of element-wise transfers without using heavy range method.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Check invariant over size() and range()

contrib/coco/core/include/coco/IR/Shuffle.h
contrib/coco/core/src/IR/Shuffle.cpp
contrib/coco/core/src/IR/Shuffle.test.cpp

index cc22b9f..8a9cb2b 100644 (file)
@@ -43,6 +43,11 @@ public:
   void into(Bag *);
 
 public:
+  // @brief Return the number of Element-wise transfers
+  //
+  // NOTE size() SHOULD BE identical to range().size()
+  uint32_t size(void) const;
+
   // @brief Return a set of elements in the destination bag that Shuffle will update
   std::set<ElemID> range(void) const;
 
index 9fd5873..8e362b9 100644 (file)
@@ -15,6 +15,8 @@ std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, coco::Bag *b)
 namespace coco
 {
 
+uint32_t Shuffle::size(void) const { return _content.size(); }
+
 std::set<ElemID> Shuffle::range(void) const
 {
   std::set<ElemID> res;
index 813fe18..a4ce2a8 100644 (file)
@@ -48,6 +48,17 @@ TEST_F(ShuffleTest, asShuffle)
   ASSERT_EQ(mutable_ptr->asShuffle(), immutable_ptr->asShuffle());
 }
 
+TEST_F(ShuffleTest, size)
+{
+  auto shuffle = allocate();
+
+  shuffle->insert(coco::ElemID{3}, coco::ElemID{2});
+  shuffle->insert(coco::ElemID{3}, coco::ElemID{5});
+
+  ASSERT_EQ(shuffle->size(), 2);
+  ASSERT_EQ(shuffle->range().size(), shuffle->size());
+}
+
 TEST_F(ShuffleTest, range)
 {
   auto shuffle = allocate();