[coco] Introduce Shuffle::range (#1400)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Fri, 7 Sep 2018 02:12:31 +0000 (11:12 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 7 Sep 2018 02:12:31 +0000 (11:12 +0900)
This commit extends Shuffle class with range method which returns the
set of elements that will be updated by Shuffle.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Shuffle.h
contrib/coco/core/src/IR/Shuffle.cpp
contrib/coco/core/src/IR/Shuffle.test.cpp

index 759ced7..f5ad240 100644 (file)
@@ -10,6 +10,7 @@
 #include "coco/ADT/PtrLink.h"
 
 #include <map>
+#include <set>
 
 namespace coco
 {
@@ -46,6 +47,10 @@ public:
   void into(Bag *);
 
 public:
+  // @brief Return a set of elements in the destination bag that Shuffle will update
+  std::set<ElemID> range(void) const;
+
+public:
   /**
    * Let M be the return of at(N). This means that N-th element in the destination
    * bag will be filled with the value of M-th element in the source bag.
index afa1926..3accd5e 100644 (file)
@@ -15,6 +15,18 @@ std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, coco::Bag *b)
 namespace coco
 {
 
+std::set<ElemID> Shuffle::range(void) const
+{
+  std::set<ElemID> res;
+
+  for (auto it = _content.begin(); it != _content.end(); ++it)
+  {
+    res.insert(it->first);
+  }
+
+  return res;
+}
+
 void Shuffle::insert(const ElemID &from, const ElemID &into) { _content[into] = from; }
 
 std::set<Bag *> Shuffle::reads(void) const
index 768d82f..c637cf7 100644 (file)
@@ -48,3 +48,17 @@ TEST_F(ShuffleTest, asShuffle)
   ASSERT_NE(mutable_ptr->asShuffle(), nullptr);
   ASSERT_EQ(mutable_ptr->asShuffle(), immutable_ptr->asShuffle());
 }
+
+TEST_F(ShuffleTest, range)
+{
+  auto shuffle = allocate();
+
+  shuffle->insert(coco::ElemID{3}, coco::ElemID{2});
+  shuffle->insert(coco::ElemID{3}, coco::ElemID{5});
+
+  auto range = shuffle->range();
+
+  EXPECT_EQ(range.size(), 2);
+  EXPECT_NE(range.count(coco::ElemID{2}), 0);
+  EXPECT_NE(range.count(coco::ElemID{5}), 0);
+}