Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix, simplify, and reindent surf_*_resource_cmp functions.
[simgrid.git] / src / surf / surf_routing.c
index f607a18..e16cdfc 100644 (file)
@@ -25,7 +25,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 routing_global_t global_routing = NULL;
 routing_component_t current_routing = NULL;
 model_type_t current_routing_model = NULL;
-static double_f_pvoid_t get_link_latency = NULL;
+static double_f_cpvoid_t get_link_latency = NULL;
 
 /* Prototypes of each model */
 static void *model_full_create(void);   /* create structures for full routing model */
@@ -243,7 +243,7 @@ static void parse_S_route_new_and_endpoints(const char *src_id, const char *dst_
 }
 
 /**
- * \breif Set the endpoints for a route from XML
+ * \brief Set the endpoints for a route from XML
  */
 static void parse_S_route_new_and_endpoints_XML(void)
 {
@@ -252,7 +252,7 @@ static void parse_S_route_new_and_endpoints_XML(void)
 }
 
 /**
- * \breif Set the endpoints for a route from lua
+ * \brief Set the endpoints for a route from lua
  */
 static void parse_S_route_new_and_endpoints_lua(const char *id_src, const char *id_dst)
 {
@@ -571,8 +571,8 @@ static xbt_dynar_t elements_father(const char *src, const char *dst)
   }
 
   /* (3) find the common father */
-  index_src = (path_src->used) - 1;
-  index_dst = (path_dst->used) - 1;
+  index_src = path_src->used - 1;
+  index_dst = path_dst->used - 1;
   current_src = xbt_dynar_get_ptr(path_src, index_src);
   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
@@ -719,16 +719,13 @@ static route_extended_t _get_route(const char *src, const char *dst)
 static double _get_latency(const char *src, const char *dst)
 {
 
-  void *link;
-  unsigned int cpt = 0;
   double latency, latency_src, latency_dst = 0.0;
 
   DEBUG2("Solve route  \"%s\" to \"%s\"", src, dst);
 
   xbt_assert0(src && dst, "bad parameters for \"_get_route\" method");
 
-  route_extended_t e_route, e_route_cnt, e_route_src = NULL, e_route_dst =
-      NULL;
+  route_extended_t e_route, e_route_cnt;
 
   xbt_dynar_t elem_father_list = elements_father(src, dst);
 
@@ -1001,7 +998,7 @@ static e_surf_network_element_type_t get_network_element_type(const char
  * 
  * Make a global routing structure and set all the parsing functions.
  */
-void routing_model_create(size_t size_of_links, void *loopback, double_f_pvoid_t get_link_latency_fun  )
+void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_t get_link_latency_fun)
 {
 
   /* config the uniq global routing */
@@ -2246,9 +2243,9 @@ static void rule_route_free(void *e)
     xbt_dynar_free(&(*elem)->re_str_link);
     pcre_free((*elem)->re_src);
     pcre_free((*elem)->re_dst);
-    xbt_free((*elem));
+    xbt_free(*elem);
   }
-  (*elem) = NULL;
+  *elem = NULL;
 }
 
 static void rule_route_extended_free(void *e)
@@ -2260,7 +2257,7 @@ static void rule_route_extended_free(void *e)
     pcre_free((*elem)->generic_rule_route.re_dst);
     xbt_free((*elem)->re_src_gateway);
     xbt_free((*elem)->re_dst_gateway);
-    xbt_free((*elem));
+    xbt_free(*elem);
   }
 }
 
@@ -2777,16 +2774,14 @@ static void generic_set_autonomous_system(routing_component_t rc,
   xbt_dict_set(_to_index, name, id, xbt_free);
 }
 
-static int surf_pointer_resource_cmp(const void *a, const void *b) {
-       if(a == b)
-               return 0;
-       return 1;
+static int surf_pointer_resource_cmp(const void *a, const void *b)
+{
+  return a != b;
 }
 
-static int surf_link_resource_cmp(const void *a, const void *b) {
-       if( memcmp(a,b,global_routing->size_of_link) == 0 );
-               return 0;
-       return 1;
+static int surf_link_resource_cmp(const void *a, const void *b)
+{
+  return !!memcmp(a,b,global_routing->size_of_link);
 }
 
 static void generic_set_bypassroute(routing_component_t rc,
@@ -2877,8 +2872,8 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc,
   }
 
   /* (3) find the common father */
-  index_src = (path_src->used) - 1;
-  index_dst = (path_dst->used) - 1;
+  index_src = path_src->used - 1;
+  index_dst = path_dst->used - 1;
   current_src = xbt_dynar_get_ptr(path_src, index_src);
   current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
@@ -2891,8 +2886,8 @@ static route_extended_t generic_get_bypassroute(routing_component_t rc,
     current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
   }
 
-  int max_index_src = (path_src->used) - 1;
-  int max_index_dst = (path_dst->used) - 1;
+  int max_index_src = path_src->used - 1;
+  int max_index_dst = path_dst->used - 1;
 
   int max_index = max(max_index_src, max_index_dst);
   int i, max;