//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.26; contract Sorter { uint public totalUsers; // userID -> index mapping (uint => uint) public userMap; // string[][2] public userDetails; int[100][100][2] public adjMatrix; uint public passedTxnsCnt; uint public test; uint public testTotal; uint[] public path; constructor() public { // loopVar = initVal*50; totalUsers = 0; passedTxnsCnt = 0; // for (uint i = 0; i < 100; i++){ // for (uint j=0; j<100; j++){ // adjMatrix[0][j][i] = -1; // adjMatrix[1][j][i] = -1; // adjMatrix[0][i][j] = -1; // adjMatrix[1][i][j] = -1; // } // } } // function runLoop() view public{ // uint a=0; // for (uint i = 0; i < loopVar; i++) // { // a++; // } // } function registerUser(uint userID, string userName) public{ // userDetails[totalUsers][0] = string(userID); // userDetails[totalUsers][0] = userName; userMap[userID] = totalUsers; for (uint i = 0; i < totalUsers; i++){ adjMatrix[0][i][totalUsers] = -1; adjMatrix[1][i][totalUsers] = -1; adjMatrix[0][totalUsers][i] = -1; adjMatrix[1][totalUsers][i] = -1; } totalUsers += 1; // testTotal = totalUsers; test=30; } function createAcc(uint userID1, uint userID2, int sampledValue) public{ // sampledValue will come from python script. Solidity doesn't have exponential dist. // The sampled value must be an even integer (solidity doesn't support float/double either) adjMatrix[0][userMap[userID1]][userMap[userID2]] = sampledValue/2; adjMatrix[1][userMap[userID1]][userMap[userID2]] = sampledValue/2; adjMatrix[0][userMap[userID2]][userMap[userID1]] = sampledValue/2; adjMatrix[1][userMap[userID2]][userMap[userID1]] = sampledValue/2; test=22; } function sendAmount(uint userID1, uint userID2) public{ // find the shortest path between userMap[userID1], userMap[userID2] // path = [a, b, c, d]; a->d test=99; uint temp = totalUsers; uint[] memory visited = new uint[](temp); uint[] queue; uint ii; uint[] memory dist = new uint[](temp); int[] memory parent = new int[](temp); for (uint i=0;i<temp;i++){ dist[i] = 1000; parent[i] = -1; visited[i] = 0; } uint src = userMap[userID1]; uint dest = userMap[userID2]; test=totalUsers; queue.push(src); visited[src] = 1; dist[src] = 0; uint flag = 0; uint len = queue.length; while (len>0){ // test -= 1; uint node = queue[0+ii]; len -= 1; // delete queue[0]; ii += 1; for (i = 0; i<totalUsers; i++){ if (!(adjMatrix[0][i][node] == -1 && adjMatrix[1][i][node] == -1) && adjMatrix[0][i][node] >= 1){ // test -= 1; if (visited[i] == 0){ visited[i] = 1; dist[i] = dist[node] + 1; parent[i] = int(node); queue.push(i); len += 1; if (i == dest){ flag = 1; break; } } } } } totalUsers = test; delete path; if (flag == 0){ // print("no path found"); } else{ // uint size = 0; passedTxnsCnt += 1; node = dest; while (node != src){ path.push(node); // size += 1; node = uint(parent[node]); } path.push(src); // size += 1; // return path; } // uint[] path = shortestPath(userID1, userID2); for (i = 0; i < path.length - 1; i++){ adjMatrix[0][path[i]][path[i+1]] -= 1; adjMatrix[1][path[i]][path[i+1]] += 1; adjMatrix[0][path[i+1]][path[i]] += 1; adjMatrix[1][path[i+1]][path[i]] -= 1; } } function closeAcc(uint userID1, uint userID2) public{ adjMatrix[userMap[userID1]][userMap[userID2]][0] = -1; adjMatrix[userMap[userID1]][userMap[userID2]][1] = -1; } function getTxStatus() public view returns(uint){ return passedTxnsCnt; } }
0.4.24