+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
99f4f39
master
1package clocks ; 2public class MatrixClock { 3int [][]M ; 4int myId ; 5int N ; 6public MatrixClock (int numProc ,int id ) { 7myId =id ; 8N =numProc ; 9M =new int [N ][N ]; 10for (int i =0 ;i <N ;i ++) 11for (int j =0 ;j <N ;j ++) 12M [i ][j ] =0 ; 13M [myId ][myId ] =1 ; 14 } 15public void tick () { 16M [myId ][myId ]++; 17 } 18public void sendAction () { 19//include the matrix in the message 20M [myId ][myId ]++; 21 } 22public void receiveAction (int [][]W ,int srcId ) { 23// component-wise maximum of matrices 24for (int i =0 ;i <N ;i ++) 25if (i !=myId ) { 26for (int j =0 ;j <N ;j ++) 27M [i ][j ] =Math .max (M [i ][j ],W [i ][j ]); 28 } 29 30// update the vector for this process 31for (int j =0 ;j <N ;j ++) 32M [myId ][j ] =Math .max (M [myId ][j ],W [srcId ][j ]); 33 34M [myId ][myId ]++; 35 } 36public int getValue (int i ,int j ) { 37return M [i ][j ]; 38 } 39}