!2662 Optimized TopoSort

Merge pull request !2662 from Kang/opt
This commit is contained in:
mindspore-ci-bot 2020-06-29 09:30:07 +08:00 committed by Gitee
commit 77d23a1b17
1 changed files with 4 additions and 2 deletions

View File

@ -23,10 +23,10 @@
#include <utility> #include <utility>
#include <stack> #include <stack>
#include <vector> #include <vector>
#include <list>
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <queue> #include <queue>
#include <deque>
#include <set> #include <set>
#include "common/utils.h" #include "common/utils.h"
@ -37,9 +37,11 @@
namespace mindspore { namespace mindspore {
std::vector<AnfNodePtr> TopoSort(const AnfNodePtr &root, const SuccFunc &succ, const IncludeFunc &include) { std::vector<AnfNodePtr> TopoSort(const AnfNodePtr &root, const SuccFunc &succ, const IncludeFunc &include) {
size_t seen = NewSeenGeneration(); size_t seen = NewSeenGeneration();
std::list<AnfNodePtr> todo(1, root); std::deque<AnfNodePtr> todo(1024);
std::unordered_map<AnfNodePtr, size_t> rank; std::unordered_map<AnfNodePtr, size_t> rank;
std::vector<AnfNodePtr> res; std::vector<AnfNodePtr> res;
todo.clear();
todo.push_back(root);
while (!todo.empty()) { while (!todo.empty()) {
AnfNodePtr node = todo.back(); AnfNodePtr node = todo.back();