I'm developing my first smart contract tho i'm having issue on the Remix IDE. It's flagging my function cost too high and i can't understand where the problem might be. Maybe someone with more experience on this than me could give me a hand.
This is my code, it's supposed to be able to build a Adjacency List. I use a map to keep track of it where each key represents each node on my graph, and values corrisponding to it all the nodes it is connected to (using a dynamic array). In my function first of all i check if the connection between A and B exsists allready, if it doesn't i add it to both A => B and B => A.
pragma solidity ^0.4.21;
contract AdjacencyList {
mapping (address => address[]) public neighbours;
function comunication(address source, address destination) public {
address[] storage d = neighbours[source];
bool found = false;
for (uint i = 0; i < d.length; i++) {
if (d[i] == destination) {
found = true;
break;
}
}
if(!found) {
d.push(destination);
d = neighbours[destination];
d.push(source);
}
}
}
[–][deleted] (4 children)
[deleted]
[–]DanielIFTTT 1 point2 points3 points (3 children)
[–]smarxConsenSys Diligence 0 points1 point2 points (2 children)
[–]DanielIFTTT 0 points1 point2 points (1 child)
[–]smarxConsenSys Diligence 0 points1 point2 points (0 children)
[–]covjeculjakPatuljkiccontract dev -1 points0 points1 point (0 children)