Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / examples / msg / dht-pastry / dht-pastry.c
index f7f0cca..a5ef7b6 100644 (file)
@@ -1,13 +1,13 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2013-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/msg.h"
 #include "xbt/dynar.h"
-#include <math.h>
 
+#include <math.h>
+#include <stdio.h>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_pastry, "Messages specific for this msg example");
 
@@ -78,9 +78,9 @@ static int closest_in_namespace_set(node_t node, int dest);
 static int routing_next(node_t node, int dest);
 
 /**
- * \brief Gets the mailbox name of a host given its chord id.
- * \param node_id id of a node
- * \param mailbox pointer to where the mailbox name should be written
+ * @brief Gets the mailbox name of a host given its chord id.
+ * @param node_id id of a node
+ * @param mailbox pointer to where the mailbox name should be written
  * (there must be enough space)
  */
 static void get_mailbox(int node_id, char* mailbox)
@@ -312,7 +312,7 @@ static void handle_task(node_t node, msg_task_t task) {
       // if the node is ready, do all the pending tasks and send update to known nodes
       if (node->ready==0) {
         XBT_DEBUG("Node %i is ready!!!", node->id);
-        while(xbt_dynar_length(node->pending_tasks)){
+        while (!xbt_dynar_is_empty(node->pending_tasks)) {
           msg_task_t task;
           xbt_dynar_shift(node->pending_tasks, &task);
           handle_task(node, task);
@@ -378,16 +378,13 @@ static void handle_task(node_t node, msg_task_t task) {
       // add lower elements
       j = NAMESPACE_SIZE/2-1;
       for (i=NAMESPACE_SIZE/2-1; i>=0; i--) {
-        if (min<0) {
+        if (min < 0 || curr_namespace_set[j] > task_namespace_set[min]) {
           node->namespace_set[i] = curr_namespace_set[j];
           j--;
         } else if (curr_namespace_set[j] == task_namespace_set[min]) {
           node->namespace_set[i] = curr_namespace_set[j];
           j--;
           min--;
-        } else if (curr_namespace_set[j] > task_namespace_set[min]) {
-          node->namespace_set[i] = curr_namespace_set[j];
-          j--;
         } else {
           node->namespace_set[i] = task_namespace_set[min];
           min--;
@@ -401,19 +398,16 @@ static void handle_task(node_t node, msg_task_t task) {
          node->namespace_set[i] = curr_namespace_set[j];
          j++;
         } else if (max >= 0){
-          if (curr_namespace_set[j] == -1) {
+          if (curr_namespace_set[j] == -1 || curr_namespace_set[j] > task_namespace_set[max]) {
             node->namespace_set[i] = task_namespace_set[max];
             max++;
           } else if (curr_namespace_set[j] == task_namespace_set[max]) {
             node->namespace_set[i] = curr_namespace_set[j];
             j++;
             max++;
-          } else if (curr_namespace_set[j] < task_namespace_set[max]) {
+          } else {
             node->namespace_set[i] = curr_namespace_set[j];
             j++;
-          } else {
-            node->namespace_set[i] = task_namespace_set[max];
-            max++;
           }
         }
       }
@@ -455,7 +449,7 @@ static int join(node_t node){
 }
 
 /**
- * \brief Node Function
+ * @brief Node Function
  * Arguments:
  * - my id
  * - the id of a guy I know in the system (except for the first node)
@@ -552,7 +546,7 @@ static int node(int argc, char *argv[])
   return 1;
 }
 
-/** \brief Main function. */
+/** @brief Main function. */
 int main(int argc, char *argv[])
 {
   MSG_init(&argc, argv);