A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace while+modulo by a bitwise operation
[simgrid.git]
/
examples
/
msg
/
chord
/
chord.c
diff --git
a/examples/msg/chord/chord.c
b/examples/msg/chord/chord.c
index
138a609
..
08698f6
100644
(file)
--- a/
examples/msg/chord/chord.c
+++ b/
examples/msg/chord/chord.c
@@
-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);
}
/**
}
/**