From 6bb41d92e3329c3be26c100026424ed3885d8554 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 10 May 2022 21:24:06 +0200 Subject: [PATCH] Make helper functions static members of NetZoneImpl. --- .../simgrid/kernel/routing/NetZoneImpl.hpp | 5 +++ include/simgrid/kernel/routing/RoutedZone.hpp | 5 --- src/kernel/routing/NetZoneImpl.cpp | 26 +++++++++++++++ src/kernel/routing/RoutedZone.cpp | 33 ------------------- src/kernel/routing/StarZone.cpp | 1 - 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index d0c312a806..e03fcf8296 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -119,6 +119,11 @@ protected: std::vector get_link_list_impl(const std::vector& link_list, bool backroute) const; + static xbt_node_t new_xbt_graph_node(const s_xbt_graph_t* graph, const char* name, + std::map>* nodes); + static xbt_edge_t new_xbt_graph_edge(const s_xbt_graph_t* graph, xbt_node_t src, xbt_node_t dst, + std::map>* edges); + public: enum class RoutingMode { base, /**< Base case: use simple link lists for routing */ diff --git a/include/simgrid/kernel/routing/RoutedZone.hpp b/include/simgrid/kernel/routing/RoutedZone.hpp index 31f02ea09f..c086cea71f 100644 --- a/include/simgrid/kernel/routing/RoutedZone.hpp +++ b/include/simgrid/kernel/routing/RoutedZone.hpp @@ -66,9 +66,4 @@ protected: } // namespace kernel } // namespace simgrid -XBT_PRIVATE xbt_node_t new_xbt_graph_node(const s_xbt_graph_t* graph, const char* name, - std::map>* nodes); -XBT_PRIVATE xbt_edge_t new_xbt_graph_edge(const s_xbt_graph_t* graph, xbt_node_t s, xbt_node_t d, - std::map>* edges); - #endif /* SIMGRID_ROUTING_GENERIC_HPP_ */ diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index ef3f4e3684..95f9028156 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -125,6 +125,32 @@ NetZoneImpl::~NetZoneImpl() s4u::Engine::get_instance()->netpoint_unregister(netpoint_); } +xbt_node_t NetZoneImpl::new_xbt_graph_node(const s_xbt_graph_t* graph, const char* name, + std::map>* nodes) +{ + auto [elm, inserted] = nodes->try_emplace(name); + if (inserted) + elm->second = xbt_graph_new_node(graph, xbt_strdup(name)); + return elm->second; +} + +xbt_edge_t NetZoneImpl::new_xbt_graph_edge(const s_xbt_graph_t* graph, xbt_node_t src, xbt_node_t dst, + std::map>* edges) +{ + const auto* src_name = static_cast(xbt_graph_node_get_data(src)); + const auto* dst_name = static_cast(xbt_graph_node_get_data(dst)); + + auto elm = edges->find(std::string(src_name) + dst_name); + if (elm == edges->end()) { + bool inserted; + std::tie(elm, inserted) = edges->try_emplace(std::string(dst_name) + src_name); + if (inserted) + elm->second = xbt_graph_new_edge(graph, src, dst, nullptr); + } + + return elm->second; +} + void NetZoneImpl::add_child(NetZoneImpl* new_zone) { xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname()); diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index 6d078d78cd..27fbd27fcd 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -16,39 +16,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_generic, ker_routing, "Kernel Generi /* ***************************************************************** */ /* *********************** GENERIC METHODS ************************* */ -xbt_node_t new_xbt_graph_node(const s_xbt_graph_t* graph, const char* name, - std::map>* nodes) -{ - auto elm = nodes->find(name); - if (elm == nodes->end()) { - xbt_node_t ret = xbt_graph_new_node(graph, xbt_strdup(name)); - nodes->insert({name, ret}); - return ret; - } else - return elm->second; -} - -xbt_edge_t new_xbt_graph_edge(const s_xbt_graph_t* graph, xbt_node_t s, xbt_node_t d, - std::map>* edges) -{ - const auto* sn = static_cast(xbt_graph_node_get_data(s)); - const auto* dn = static_cast(xbt_graph_node_get_data(d)); - std::string name = std::string(sn) + dn; - - auto elm = edges->find(name); - if (elm == edges->end()) { - name = std::string(dn) + sn; - elm = edges->find(name); - } - - if (elm == edges->end()) { - xbt_edge_t ret = xbt_graph_new_edge(graph, s, d, nullptr); - edges->insert({name, ret}); - return ret; - } else - return elm->second; -} - namespace simgrid::kernel::routing { RoutedZone::RoutedZone(const std::string& name) : NetZoneImpl(name) {} diff --git a/src/kernel/routing/StarZone.cpp b/src/kernel/routing/StarZone.cpp index c223e25597..16b72625a8 100644 --- a/src/kernel/routing/StarZone.cpp +++ b/src/kernel/routing/StarZone.cpp @@ -5,7 +5,6 @@ #include "simgrid/kernel/routing/StarZone.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" -#include "simgrid/kernel/routing/RoutedZone.hpp" #include "src/kernel/resource/NetworkModel.hpp" #include "xbt/string.hpp" -- 2.20.1