Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / ir / OperandIndexSequence.h
index 1f5ab3d..aa01ecc 100644 (file)
@@ -27,6 +27,12 @@ namespace onert
 namespace ir
 {
 
+enum class Remove
+{
+  DUPLICATED = 1,
+  UNDEFINED = 2
+};
+
 class OperandIndexSequence
 {
 public:
@@ -36,25 +42,49 @@ public:
   OperandIndexSequence(std::initializer_list<uint32_t> list);
 
 public:
-  void append(const OperandIndex &index) { _set.emplace_back(index); }
-  void append(const OperandIndexSequence &l) { _set.insert(_set.end(), l.begin(), l.end()); }
+  void append(const OperandIndex &index) { _vec.emplace_back(index); }
+  void append(const OperandIndexSequence &l) { _vec.insert(_vec.end(), l.begin(), l.end()); }
 
 public:
-  uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
-  const OperandIndex &at(IOIndex set_index) const { return _set.at(set_index.value()); }
-  const OperandIndex &at(uint32_t index) const { return _set.at(index); }
+  uint32_t size() const { return static_cast<uint32_t>(_vec.size()); }
+  const OperandIndex &at(IOIndex set_index) const { return _vec.at(set_index.value()); }
+  const OperandIndex &at(uint32_t index) const { return _vec.at(index); }
   bool contains(const OperandIndex &index) const;
   void replace(const OperandIndex &from, const OperandIndex &to);
+  OperandIndexSequence operator|(ir::Remove filter) const
+  {
+    switch (filter)
+    {
+      case ir::Remove::DUPLICATED:
+      {
+        ir::OperandIndexSequence seq;
+        for (const auto &ind : _vec)
+          if (!seq.contains(ind))
+            seq.append(ind);
+        return seq;
+      }
+      case ir::Remove::UNDEFINED:
+      {
+        ir::OperandIndexSequence seq;
+        for (const auto &ind : _vec)
+          if (!ind.undefined())
+            seq.append(ind);
+        return seq;
+      }
+    }
+    return *this;
+  }
 
 public:
   OperandIndexSequence operator+(const OperandIndexSequence &other) const;
+  friend std::ostream &operator<<(std::ostream &o, const OperandIndexSequence &op_seq);
 
 public:
-  std::vector<OperandIndex>::const_iterator begin(void) const { return _set.begin(); }
-  std::vector<OperandIndex>::const_iterator end(void) const { return _set.end(); }
+  std::vector<OperandIndex>::const_iterator begin(void) const { return _vec.begin(); }
+  std::vector<OperandIndex>::const_iterator end(void) const { return _vec.end(); }
 
 private:
-  std::vector<OperandIndex> _set;
+  std::vector<OperandIndex> _vec;
 };
 
 } // namespace ir