From f602ee5e834cf7bf6d1e1be849daae79a54e7274 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 16 Nov 2016 01:40:07 +0100 Subject: [PATCH 1/1] code simplification: write the recursivity properly --- src/kernel/routing/AsImpl.cpp | 7 +++++++ src/kernel/routing/AsRoutedGraph.cpp | 3 ++- src/surf/surf_routing.cpp | 16 +--------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/kernel/routing/AsImpl.cpp b/src/kernel/routing/AsImpl.cpp index 9fe0cefa82..a0841b9414 100644 --- a/src/kernel/routing/AsImpl.cpp +++ b/src/kernel/routing/AsImpl.cpp @@ -43,6 +43,13 @@ namespace simgrid { void AsImpl::getOneLinkRoutes(std::vector* accumulator) { + // recursing only. I have no route myself :) + char* key; + xbt_dict_cursor_t cursor = nullptr; + AsImpl* rc_child; + xbt_dict_foreach (children(), cursor, key, rc_child) { + rc_child->getOneLinkRoutes(accumulator); + } } /** @brief Get the common ancestor and its first children in each line leading to src and dst diff --git a/src/kernel/routing/AsRoutedGraph.cpp b/src/kernel/routing/AsRoutedGraph.cpp index 592ad3c46d..20b0910b8a 100644 --- a/src/kernel/routing/AsRoutedGraph.cpp +++ b/src/kernel/routing/AsRoutedGraph.cpp @@ -107,7 +107,8 @@ void AsRoutedGraph::getOneLinkRoutes(std::vector* accumulator) } } } - } + AsImpl::getOneLinkRoutes(accumulator); // Recursivly call this function on all my childs too +} void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) { diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index b1b6a12342..d4cd3d5273 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -100,24 +100,10 @@ void RoutingPlatf::getRouteAndLatency(NetCard *src, NetCard *dst, std::vector
  • * accumulator) -{ - //adding my one link routes - as->getOneLinkRoutes(accumulator); - - //recursing - char *key; - xbt_dict_cursor_t cursor = nullptr; - AsImpl *rc_child; - xbt_dict_foreach(as->children(), cursor, key, rc_child) { - _recursiveGetOneLinkRoutes(rc_child, accumulator); - } -} - std::vector* RoutingPlatf::getOneLinkRoutes() { std::vector* res = new std::vector(); - _recursiveGetOneLinkRoutes(root_, res); + root_->getOneLinkRoutes(res); return res; } -- 2.20.1