Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making quasilinear complexity implementation linear #3605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <map>
#include <functional>
#include <memory>
#include <unordered_map>
#include <unordered_set>


//
// Header only algorithms for working with execution graphs.
Expand Down Expand Up @@ -139,7 +142,7 @@ namespace CNTK
// collected nodes.
//
template<class TNode>
static void PostOrderTraversalImpl(const DirectedGraph<TNode>& graph, const TNode& node, std::set<TNode>& visited, std::list<TNode>& result)
static void PostOrderTraversalImpl(const DirectedGraph<TNode>& graph, const TNode& node, std::unordered_set<TNode>& visited, std::list<TNode>& result)
{
if (visited.find(node) != visited.end())
return;
Expand Down Expand Up @@ -175,7 +178,7 @@ namespace CNTK
const TNode& node,
std::stack<TNode>& nodeStack,
int& index,
std::map<TNode, Internal::StrongComponentNodeState>& state,
std::unordered_map<TNode, Internal::StrongComponentNodeState>& state,
std::vector<StrongComponent<TNode>>& strongComponents)
{
assert(!state[node].m_visited);
Expand Down Expand Up @@ -299,7 +302,7 @@ namespace CNTK
inline std::list<TNode> PostOrderTraversal(const DirectedGraph<TNode>& graph, const std::vector<TNode>& startNodes)
{
std::list<TNode> result;
std::set<TNode> visited;
std::unordered_set<TNode> visited;
for (const auto& node : startNodes)
Internal::PostOrderTraversalImpl(graph, node, visited, result);
return result;
Expand All @@ -311,7 +314,7 @@ namespace CNTK
template<class TNode>
std::vector<StrongComponent<TNode>> StrongComponents(const DirectedGraph<TNode>& graph)
{
std::map<TNode, Internal::StrongComponentNodeState> state;
std::unordered_map<TNode, Internal::StrongComponentNodeState> state;
std::vector<StrongComponent<TNode>> result;
std::stack<TNode> nodeStack;
int index = 0;
Expand Down Expand Up @@ -419,4 +422,4 @@ namespace CNTK
}
return result;
}
}
}