From b653e7148ee43302c8fb14eebb05f02f7e236231 Mon Sep 17 00:00:00 2001 From: utsab Date: Tue, 19 Mar 2019 19:49:37 +0530 Subject: [PATCH] making quasilinear implementation linear --- .../API/Internals/ComputationGraphAlgorithms.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/CNTKv2LibraryDll/API/Internals/ComputationGraphAlgorithms.h b/Source/CNTKv2LibraryDll/API/Internals/ComputationGraphAlgorithms.h index e8bf371bb1f0..884f8927ae0a 100644 --- a/Source/CNTKv2LibraryDll/API/Internals/ComputationGraphAlgorithms.h +++ b/Source/CNTKv2LibraryDll/API/Internals/ComputationGraphAlgorithms.h @@ -11,6 +11,9 @@ #include #include #include +#include +#include + // // Header only algorithms for working with execution graphs. @@ -139,7 +142,7 @@ namespace CNTK // collected nodes. // template - static void PostOrderTraversalImpl(const DirectedGraph& graph, const TNode& node, std::set& visited, std::list& result) + static void PostOrderTraversalImpl(const DirectedGraph& graph, const TNode& node, std::unordered_set& visited, std::list& result) { if (visited.find(node) != visited.end()) return; @@ -175,7 +178,7 @@ namespace CNTK const TNode& node, std::stack& nodeStack, int& index, - std::map& state, + std::unordered_map& state, std::vector>& strongComponents) { assert(!state[node].m_visited); @@ -299,7 +302,7 @@ namespace CNTK inline std::list PostOrderTraversal(const DirectedGraph& graph, const std::vector& startNodes) { std::list result; - std::set visited; + std::unordered_set visited; for (const auto& node : startNodes) Internal::PostOrderTraversalImpl(graph, node, visited, result); return result; @@ -311,7 +314,7 @@ namespace CNTK template std::vector> StrongComponents(const DirectedGraph& graph) { - std::map state; + std::unordered_map state; std::vector> result; std::stack nodeStack; int index = 0; @@ -419,4 +422,4 @@ namespace CNTK } return result; } -} \ No newline at end of file +}