From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Wed, 5 Sep 2018 08:03:56 +0000 (+0900) Subject: [neurun] Use unordered_map instead of map (#2605) X-Git-Tag: 0.2~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=018d3dc1d3bac82604e236a14d394c01c1ba9099;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Use unordered_map instead of map (#2605) 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 --- diff --git a/runtimes/neurun/src/graph/operand/Set.cc b/runtimes/neurun/src/graph/operand/Set.cc index c5cc17b..862e011 100644 --- a/runtimes/neurun/src/graph/operand/Set.cc +++ b/runtimes/neurun/src/graph/operand/Set.cc @@ -20,14 +20,14 @@ Index Set::append(const Shape &shape, const TypeInfo &type) { auto index = generateIndex(); - _objects[index.asInt()] = nnfw::make_unique(shape, type); + _objects[index] = nnfw::make_unique(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(); } diff --git a/runtimes/neurun/src/graph/operand/Set.h b/runtimes/neurun/src/graph/operand/Set.h index f618a17..754aec1 100644 --- a/runtimes/neurun/src/graph/operand/Set.h +++ b/runtimes/neurun/src/graph/operand/Set.h @@ -2,7 +2,7 @@ #define __NEURUN_GRAPH_OPERAND_SET_H__ #include -#include +#include #include "Object.h" #include "Index.h" @@ -31,7 +31,7 @@ private: const Index generateIndex(); private: - std::map> _objects; + std::unordered_map> _objects; uint32_t _index_count; }; diff --git a/runtimes/neurun/src/graph/operation/Set.cc b/runtimes/neurun/src/graph/operation/Set.cc index 9870ec4..d12bc39 100644 --- a/runtimes/neurun/src/graph/operation/Set.cc +++ b/runtimes/neurun/src/graph/operation/Set.cc @@ -20,21 +20,21 @@ Index Set::append(std::unique_ptr &&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 &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 &fn) { for (auto it = _nodes.begin(); it != _nodes.end(); ++it) { - fn(Index{it->first}, *it->second); + fn(it->first, *it->second); } } diff --git a/runtimes/neurun/src/graph/operation/Set.h b/runtimes/neurun/src/graph/operation/Set.h index 8a42a30..518907b 100644 --- a/runtimes/neurun/src/graph/operation/Set.h +++ b/runtimes/neurun/src/graph/operation/Set.h @@ -6,7 +6,7 @@ #include "graph/operation/Index.h" #include "Node.h" -#include +#include namespace neurun { @@ -35,7 +35,7 @@ private: const Index generateIndex(); private: - std::map> _nodes; + std::unordered_map> _nodes; uint32_t _index_count; }; diff --git a/runtimes/neurun/src/internal/BackendManager.h b/runtimes/neurun/src/internal/BackendManager.h index 7e2ab3d..98d1926 100644 --- a/runtimes/neurun/src/internal/BackendManager.h +++ b/runtimes/neurun/src/internal/BackendManager.h @@ -2,6 +2,7 @@ #define __INTERNAL_BACKEND_MANAGER_H__ #include +#include #include "graph/operand/Set.h"