Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make helper functions static members of NetZoneImpl.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 10 May 2022 19:24:06 +0000 (21:24 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 10 May 2022 19:47:04 +0000 (21:47 +0200)
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/kernel/routing/RoutedZone.hpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/kernel/routing/StarZone.cpp

index d0c312a..e03fcf8 100644 (file)
@@ -119,6 +119,11 @@ protected:
   std::vector<resource::StandardLinkImpl*> get_link_list_impl(const std::vector<s4u::LinkInRoute>& link_list,
                                                               bool backroute) const;
 
+  static xbt_node_t new_xbt_graph_node(const s_xbt_graph_t* graph, const char* name,
+                                       std::map<std::string, xbt_node_t, std::less<>>* 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<std::string, xbt_edge_t, std::less<>>* edges);
+
 public:
   enum class RoutingMode {
     base,     /**< Base case: use simple link lists for routing     */
index 31f02ea..c086cea 100644 (file)
@@ -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<std::string, xbt_node_t, std::less<>>* 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<std::string, xbt_edge_t, std::less<>>* edges);
-
 #endif /* SIMGRID_ROUTING_GENERIC_HPP_ */
index ef3f4e3..95f9028 100644 (file)
@@ -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<std::string, xbt_node_t, std::less<>>* 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<std::string, xbt_edge_t, std::less<>>* edges)
+{
+  const auto* src_name = static_cast<const char*>(xbt_graph_node_get_data(src));
+  const auto* dst_name = static_cast<const char*>(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());
index 6d078d7..27fbd27 100644 (file)
@@ -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<std::string, xbt_node_t, std::less<>>* 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<std::string, xbt_edge_t, std::less<>>* edges)
-{
-  const auto* sn   = static_cast<const char*>(xbt_graph_node_get_data(s));
-  const auto* dn   = static_cast<const char*>(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) {}
index c223e25..16b7262 100644 (file)
@@ -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"