[neurun] Use unordered_map instead of map (#2605)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 5 Sep 2018 08:03:56 +0000 (17:03 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 5 Sep 2018 08:03:56 +0000 (17:03 +0900)
Update `operand::Set` and `operation::Set` to use `std::unordered_map`
rather than `std::map`. Also update use key as Index instead of `int`.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/operand/Set.cc
runtimes/neurun/src/graph/operand/Set.h
runtimes/neurun/src/graph/operation/Set.cc
runtimes/neurun/src/graph/operation/Set.h
runtimes/neurun/src/internal/BackendManager.h

index c5cc17b..862e011 100644 (file)
@@ -20,14 +20,14 @@ Index Set::append(const Shape &shape, const TypeInfo &type)
 {
   auto index = generateIndex();
 
-  _objects[index.asInt()] = nnfw::make_unique<Object>(shape, type);
+  _objects[index] = nnfw::make_unique<Object>(shape, type);
 
   return index;
 }
 
-const Object &Set::at(const Index &index) const { return *(_objects.at(index.asInt())); }
+const Object &Set::at(const Index &index) const { return *(_objects.at(index)); }
 
-Object &Set::at(const Index &index) { return *(_objects.at(index.asInt())); }
+Object &Set::at(const Index &index) { return *(_objects.at(index)); }
 
 bool Set::exist(const Index &index) const { return index.value() < _objects.size(); }
 
index f618a17..754aec1 100644 (file)
@@ -2,7 +2,7 @@
 #define __NEURUN_GRAPH_OPERAND_SET_H__
 
 #include <memory>
-#include <map>
+#include <unordered_map>
 
 #include "Object.h"
 #include "Index.h"
@@ -31,7 +31,7 @@ private:
   const Index generateIndex();
 
 private:
-  std::map<uint32_t, std::unique_ptr<Object>> _objects;
+  std::unordered_map<Index, std::unique_ptr<Object>> _objects;
   uint32_t _index_count;
 };
 
index 9870ec4..d12bc39 100644 (file)
@@ -20,21 +20,21 @@ Index Set::append(std::unique_ptr<Node> &&node)
 {
   auto index = generateIndex();
 
-  _nodes[index.value()] = std::move(node);
+  _nodes[index] = std::move(node);
   return index;
 }
 
-const Node &Set::at(const Index &index) const { return *(_nodes.at(index.value())); }
+const Node &Set::at(const Index &index) const { return *(_nodes.at(index)); }
 
-Node &Set::at(const Index &index) { return *(_nodes.at(index.value())); }
+Node &Set::at(const Index &index) { return *(_nodes.at(index)); }
 
-bool Set::exist(const Index &index) const { return _nodes.find(index.value()) != _nodes.end(); }
+bool Set::exist(const Index &index) const { return _nodes.find(index) != _nodes.end(); }
 
 void Set::iterate(const std::function<void(const Index &, const Node &)> &fn) const
 {
   for (auto it = _nodes.begin(); it != _nodes.end(); ++it)
   {
-    fn(Index{it->first}, *it->second);
+    fn(it->first, *it->second);
   }
 }
 
@@ -42,7 +42,7 @@ void Set::iterate(const std::function<void(const Index &, Node &)> &fn)
 {
   for (auto it = _nodes.begin(); it != _nodes.end(); ++it)
   {
-    fn(Index{it->first}, *it->second);
+    fn(it->first, *it->second);
   }
 }
 
index 8a42a30..518907b 100644 (file)
@@ -6,7 +6,7 @@
 #include "graph/operation/Index.h"
 #include "Node.h"
 
-#include <map>
+#include <unordered_map>
 
 namespace neurun
 {
@@ -35,7 +35,7 @@ private:
   const Index generateIndex();
 
 private:
-  std::map<uint32_t, std::unique_ptr<Node>> _nodes;
+  std::unordered_map<Index, std::unique_ptr<Node>> _nodes;
   uint32_t _index_count;
 };
 
index 7e2ab3d..98d1926 100644 (file)
@@ -2,6 +2,7 @@
 #define __INTERNAL_BACKEND_MANAGER_H__
 
 #include <memory>
+#include <map>
 
 #include "graph/operand/Set.h"