Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace while+modulo by a bitwise operation
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 23 Jan 2011 20:16:23 +0000 (20:16 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 23 Jan 2011 20:16:23 +0000 (20:16 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9475 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/msg/chord/chord.c

index 138a609..08698f6 100644 (file)
@@ -131,14 +131,8 @@ static void chord_initialize(void)
  */
 static int normalize(int id)
 {
  */
 static int normalize(int id)
 {
-  // make sure id >= 0
-  while (id < 0) {
-    id += nb_keys;
-  }
-  // make sure id < nb_keys
-  id = id % nb_keys;
-
-  return id;
+  // like id % nb_keys, but works with negatives numbers (and faster)
+  return id & (nb_keys - 1);
 }
 
 /**
 }
 
 /**