Yes, the quickest and dirty-ish solution would be to use a conditional branch. Something like this:
void Grid::calculateActualCosts() {
unsigned last_i = 0;
unsigned last_j = 0;
if(readingFromFile())
{
last_i = getLastI();
last_j = getLastJ();
}
unsigned i = 0;
unsigned j = 0;
for (auto& walkable : m_walkables) {
j = 0;
if(i++ < last_i)
continue;
for (auto& walkables : m_walkables) {
if(j++ < last_j)
continue;
AStarNode* fromNode = acquireNode(...);
AStarNode* toNode = acquireNode(...);
AStarNodePair pair(fromNode, toNode);
///
astar(fromNode, toNode, totalCost);
actualCosts.insert(std::make_pair(pair, totalCost));
}
}
}
Or, you could keep an std::set<std::pair<walkable, walkable>>. If a pair of any two walkables is in the set, it has been processed already and you can just do a continue, like this:
for (auto& walkables : m_walkables) {
if(progressSet.count({walkable, walkables}))
continue;
AStarNode* fromNode = acquireNode(...);
AStarNode* toNode = acquireNode(...);
AStarNodePair pair(fromNode, toNode);
///
astar(fromNode, toNode, totalCost);
actualCosts.insert(std::make_pair(pair, totalCost));
progressSet.insert({walkable, walkables});
}
At the beginning of the function you'd start with an empty set, and if you are continuing, read the set from a file.
Your update2 also sounds valid, if it is practical to sort your data.
At first, a VM sounds like an overkill, but if it's something you only run on your dev computer ( I assume so ), it is the fastest way to having a solution.