+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
99f4f39
master
1package clocks ; 2import java .util .*; 3public class VectorClock { 4public int []v ; 5int myId ; 6int N ; 7public VectorClock (int numProc ,int id ) { 8myId =id ; 9N =numProc ; 10v =new int [numProc ]; 11Arrays .fill (v ,0 ); 12v [myId ] =1 ; 13 } 14public VectorClock (VectorClock vc ) { 15myId =vc .myId ;N =vc .N ;v =new int [N ]; 16for (int i =0 ;i <N ;i +=1 ) 17v [i ] =vc .v [i ]; 18 } 19 20public void tick () { 21v [myId ]++; 22 } 23public void sendAction () {//include the vector in the message 24v [myId ]++; 25 } 26public void receiveAction (int []sentValue ) { 27for (int i =0 ;i <N ;i ++) 28v [i ] =Math .max (v [i ],sentValue [i ]); 29v [myId ]++; 30 } 31public int getValue (int i ) { 32return v [i ]; 33 } 34public String toString (){ 35return Arrays .toString (v ); 36 } 37public boolean isLessThan (VectorClock vc ){ 38for (int i =0 ;i <N ;i ++){ 39if (v [i ] >vc .v [i ])return false ; 40 } 41return true ; 42 } 43public boolean isGreaterThan (VectorClock vc ){ 44return vc .isLessThan (this ); 45 } 46public boolean isIncomparableWith (VectorClock vc ){ 47return (!isLessThan (vc ) && !isGreaterThan (vc )); 48 } 49 50}