Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize common code to assemble vector<LinkImpl*> and update latency.
[simgrid.git] / src / kernel / routing / NetZoneImpl.cpp
index 5706ce1..d5dc99f 100644 (file)
@@ -212,8 +212,7 @@ void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_sr
 
   /* Build a copy that will be stored in the dict */
   auto* newRoute = new BypassRoute(gw_src, gw_dst);
-  for (auto const& link : link_list_)
-    newRoute->links.push_back(link);
+  newRoute->links.insert(newRoute->links.end(), begin(link_list_), end(link_list_));
 
   /* Store it */
   bypass_routes_.insert({{src, dst}, newRoute});
@@ -269,7 +268,7 @@ void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_sr
  *                 dst
  *  @endverbatim
  */
-static void find_common_ancestors(NetPoint* src, NetPoint* dst,
+static void find_common_ancestors(const NetPoint* src, const NetPoint* dst,
                                   /* OUT */ NetZoneImpl** common_ancestor, NetZoneImpl** src_ancestor,
                                   NetZoneImpl** dst_ancestor)
 {
@@ -329,7 +328,7 @@ static void find_common_ancestors(NetPoint* src, NetPoint* dst,
 }
 
 /* PRECONDITION: this is the common ancestor of src and dst */
-bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
+bool NetZoneImpl::get_bypass_route(const NetPoint* src, const NetPoint* dst,
                                    /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
                                    std::unordered_set<NetZoneImpl*>& netzones)
 {
@@ -341,11 +340,7 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
   if (dst->get_englobing_zone() == this && src->get_englobing_zone() == this) {
     if (bypass_routes_.find({src, dst}) != bypass_routes_.end()) {
       const BypassRoute* bypassedRoute = bypass_routes_.at({src, dst});
-      for (resource::LinkImpl* const& link : bypassedRoute->links) {
-        links.push_back(link);
-        if (latency)
-          *latency += link->get_latency();
-      }
+      add_link_latency(links, bypassedRoute->links, latency);
       XBT_DEBUG("Found a bypass route from '%s' to '%s' with %zu links", src->get_cname(), dst->get_cname(),
                 bypassedRoute->links.size());
       return true;
@@ -408,11 +403,7 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
               src->get_cname(), dst->get_cname(), bypassedRoute->links.size());
     if (src != key.first)
       get_global_route_with_netzones(src, bypassedRoute->gw_src, links, latency, netzones);
-    for (resource::LinkImpl* const& link : bypassedRoute->links) {
-      links.push_back(link);
-      if (latency)
-        *latency += link->get_latency();
-    }
+    add_link_latency(links, bypassedRoute->links, latency);
     if (dst != key.second)
       get_global_route_with_netzones(bypassedRoute->gw_dst, dst, links, latency, netzones);
     return true;
@@ -421,14 +412,14 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
   return false;
 }
 
-void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
+void NetZoneImpl::get_global_route(const NetPoint* src, const NetPoint* dst,
                                    /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency)
 {
   std::unordered_set<NetZoneImpl*> netzones;
   get_global_route_with_netzones(src, dst, links, latency, netzones);
 }
 
-void NetZoneImpl::get_global_route_with_netzones(NetPoint* src, NetPoint* dst,
+void NetZoneImpl::get_global_route_with_netzones(const NetPoint* src, const NetPoint* dst,
                                                  /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
                                                  std::unordered_set<NetZoneImpl*>& netzones)
 {
@@ -547,7 +538,7 @@ const NetZoneImpl* NetZoneImpl::get_netzone_recursive(const NetPoint* netpoint)
   if (netpoint == netpoint_)
     return this;
 
-  for (auto* children : children_) {
+  for (const auto* children : children_) {
     const NetZoneImpl* netzone = children->get_netzone_recursive(netpoint);
     if (netzone)
       return netzone;
@@ -558,16 +549,12 @@ const NetZoneImpl* NetZoneImpl::get_netzone_recursive(const NetPoint* netpoint)
 bool NetZoneImpl::is_component_recursive(const NetPoint* netpoint) const
 {
   /* check direct components */
-  for (const auto* elem : vertices_) {
-    if (elem == netpoint)
-      return true;
-  }
+  if (std::any_of(begin(vertices_), end(vertices_), [netpoint](const auto* elem) { return elem == netpoint; }))
+    return true;
+
   /* check childrens */
-  for (const auto* children : children_) {
-    if (children->is_component_recursive(netpoint))
-      return true;
-  }
-  return false;
+  return std::any_of(begin(children_), end(children_),
+                     [netpoint](const auto* child) { return child->is_component_recursive(netpoint); });
 }
 } // namespace routing
 } // namespace kernel