Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use std::pair instead of bprintf(%s#%s)ing the keys
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 1 Mar 2016 10:23:28 +0000 (11:23 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 1 Mar 2016 10:36:52 +0000 (11:36 +0100)
src/simdag/sd_global.cpp
src/surf/surf_routing.cpp
src/surf/surf_routing.hpp

index f8b6d50..a9e2f60 100644 (file)
@@ -50,8 +50,7 @@ void SD_init(int *argc, char **argv)
 
   surf_init(argc, argv);
 
-  xbt_cfg_setdefault_string(_sg_cfg_set, "host/model",
-                            "ptask_L07");
+  xbt_cfg_setdefault_string(_sg_cfg_set, "host/model", "ptask_L07");
 
 #ifdef HAVE_JEDULE
   jedule_sd_init();
index dffa3dc..eef8fe4 100644 (file)
@@ -132,12 +132,10 @@ namespace surf {
     std::vector<Link*> *bypassedRoute = nullptr;
 
     if(dst->containingAS() == this && src->containingAS() == this ){
-      char *route_name = bprintf("%s#%s", src->name(), dst->name());
-      if (bypassRoutes_.find(route_name) != bypassRoutes_.end()) {
-        bypassedRoute = bypassRoutes_.at(route_name);
+      if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) {
+        bypassedRoute = bypassRoutes_.at({src->name(),dst->name()});
         XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size());
       }
-      free(route_name);
       return bypassedRoute;
     }
 
@@ -171,18 +169,16 @@ namespace surf {
     for (int max = 0; max <= max_index; max++) {
       for (int i = 0; i < max; i++) {
         if (i <= max_index_src && max <= max_index_dst) {
-          char *route_name = bprintf("%s#%s", path_src.at(i)->name_, path_dst.at(max)->name_);
-          if (bypassRoutes_.find(route_name) != bypassRoutes_.end())
-            bypassedRoute = bypassRoutes_.at(route_name);
-          xbt_free(route_name);
+          const std::pair<std::string, std::string> key = {path_src.at(i)->name_, path_dst.at(max)->name_};
+          if (bypassRoutes_.find(key) != bypassRoutes_.end())
+            bypassedRoute = bypassRoutes_.at(key);
         }
         if (bypassedRoute)
           break;
         if (max <= max_index_src && i <= max_index_dst) {
-          char *route_name = bprintf("%s#%s", path_src.at(max)->name_, path_dst.at(i)->name_);
-          if (bypassRoutes_.find(route_name) != bypassRoutes_.end())
-            bypassedRoute = bypassRoutes_.at(route_name);
-          xbt_free(route_name);
+          const std::pair<std::string, std::string> key = {path_src.at(max)->name_, path_dst.at(i)->name_};
+          if (bypassRoutes_.find(key) != bypassRoutes_.end())
+            bypassedRoute = bypassRoutes_.at(key);
         }
         if (bypassedRoute)
           break;
@@ -192,10 +188,9 @@ namespace surf {
         break;
 
       if (max <= max_index_src && max <= max_index_dst) {
-        char *route_name = bprintf("%s#%s", path_src.at(max)->name_, path_dst.at(max)->name_);
-        if (bypassRoutes_.find(route_name) != bypassRoutes_.end())
-          bypassedRoute = bypassRoutes_.at(route_name);
-        xbt_free(route_name);
+        const std::pair<std::string, std::string> key = {path_src.at(max)->name_, path_dst.at(max)->name_};
+        if (bypassRoutes_.find(key) != bypassRoutes_.end())
+          bypassedRoute = bypassRoutes_.at(key);
       }
       if (bypassedRoute)
         break;
@@ -208,20 +203,18 @@ namespace surf {
     const char *src = e_route->src;
     const char *dst = e_route->dst;
 
-    char *route_name = bprintf("%s#%s", src, dst);
-
     /* Argument validity checks */
     if (e_route->gw_dst) {
       XBT_DEBUG("Load bypassASroute from %s@%s to %s@%s",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
       xbt_assert(!e_route->link_list->empty(), "Bypass route between %s@%s and %s@%s cannot be empty.",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
-      xbt_assert(bypassRoutes_.find(route_name) == bypassRoutes_.end(), "The bypass route between %s@%s and %s@%s already exists.",
+      xbt_assert(bypassRoutes_.find({src,dst}) == bypassRoutes_.end(), "The bypass route between %s@%s and %s@%s already exists.",
           src, e_route->gw_src->name(), dst, e_route->gw_dst->name());
     } else {
       XBT_DEBUG("Load bypassRoute from %s to %s", src, dst);
-      xbt_assert(!e_route->link_list->empty(),                          "Bypass route between %s and %s cannot be empty.",    src, dst);
-      xbt_assert(bypassRoutes_.find(route_name) == bypassRoutes_.end(), "The bypass route between %s and %s already exists.", src, dst);
+      xbt_assert(!e_route->link_list->empty(),                         "Bypass route between %s and %s cannot be empty.",    src, dst);
+      xbt_assert(bypassRoutes_.find({src,dst}) == bypassRoutes_.end(), "The bypass route between %s and %s already exists.", src, dst);
     }
 
     /* Build a copy that will be stored in the dict */
@@ -230,8 +223,7 @@ namespace surf {
       newRoute->push_back(link);
 
     /* Store it */
-    bypassRoutes_.insert({route_name, newRoute});
-    xbt_free(route_name);
+    bypassRoutes_.insert({{src,dst}, newRoute});
   }
 
 }} // namespace simgrid::surf
index 8d091fe..6007faf 100644 (file)
@@ -75,7 +75,7 @@ private:
   bool sealed_ = false; // We cannot add more content when sealed
 
   friend RoutingPlatf;
-  std::map<std::string, std::vector<Link*>*> bypassRoutes_;
+  std::map<std::pair<std::string, std::string>, std::vector<Link*>*> bypassRoutes_; // srcName x dstName -> route
   static void getRouteRecursive(NetCard *src, NetCard *dst, /* OUT */ std::vector<Link*> * links, double *latency);
   std::vector<Link*> *getBypassRoute(NetCard *src, NetCard *dst);