FlowStatMap: Replace RB-tree with btree-indexed vector

This commit is contained in:
Jonathan G Rennison
2019-09-28 04:20:01 +01:00
parent 0a1c1809ab
commit 90550d9642
9 changed files with 199 additions and 52 deletions

View File

@@ -146,27 +146,30 @@ void LinkGraphJob::FinaliseJob()
* somewhere. Do delete them and also reroute relevant cargo if
* automatic distribution has been turned off for that cargo. */
for (FlowStatMap::iterator it(ge.flows.begin()); it != ge.flows.end();) {
FlowStatMap::iterator new_it = flows.find(it->first);
FlowStatMap::iterator new_it = flows.find(it->GetOrigin());
if (new_it == flows.end()) {
if (_settings_game.linkgraph.GetDistributionType(this->Cargo()) != DT_MANUAL) {
it->second.Invalidate();
it->Invalidate();
++it;
} else {
FlowStat shares(INVALID_STATION, 1);
it->second.SwapShares(shares);
ge.flows.erase(it++);
FlowStat shares(INVALID_STATION, INVALID_STATION, 1);
it->SwapShares(shares);
it = ge.flows.erase(it);
for (FlowStat::SharesMap::const_iterator shares_it(shares.GetShares()->begin());
shares_it != shares.GetShares()->end(); ++shares_it) {
RerouteCargo(st, this->Cargo(), shares_it->second, st->index);
}
}
} else {
it->second.SwapShares(new_it->second);
it->SwapShares(*new_it);
flows.erase(new_it);
++it;
}
}
ge.flows.insert(flows.begin(), flows.end());
for (FlowStatMap::iterator it(flows.begin()); it != flows.end(); ++it) {
ge.flows.insert(std::move(*it));
}
ge.flows.SortStorage();
InvalidateWindowData(WC_STATION_VIEW, st->index, this->Cargo());
}
}