(svn r27612) -Codechange: Replace three uses of std::list with std::queue/vector. (JGR)

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
fonsinchen 8 years ago
parent bcdae9a093
commit e2426b22fa

@ -2,11 +2,11 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "demands.h" #include "demands.h"
#include <list> #include <queue>
#include "../safeguards.h" #include "../safeguards.h"
typedef std::list<NodeID> NodeList; typedef std::queue<NodeID> NodeList;
/** /**
* Scale various things according to symmetric/asymmetric distribution. * Scale various things according to symmetric/asymmetric distribution.
@ -172,11 +172,11 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
for (NodeID node = 0; node < job.Size(); node++) { for (NodeID node = 0; node < job.Size(); node++) {
scaler.AddNode(job[node]); scaler.AddNode(job[node]);
if (job[node].Supply() > 0) { if (job[node].Supply() > 0) {
supplies.push_back(node); supplies.push(node);
num_supplies++; num_supplies++;
} }
if (job[node].Demand() > 0) { if (job[node].Demand() > 0) {
demands.push_back(node); demands.push(node);
num_demands++; num_demands++;
} }
} }
@ -191,17 +191,17 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
while (!supplies.empty() && !demands.empty()) { while (!supplies.empty() && !demands.empty()) {
NodeID from_id = supplies.front(); NodeID from_id = supplies.front();
supplies.pop_front(); supplies.pop();
for (uint i = 0; i < num_demands; ++i) { for (uint i = 0; i < num_demands; ++i) {
assert(!demands.empty()); assert(!demands.empty());
NodeID to_id = demands.front(); NodeID to_id = demands.front();
demands.pop_front(); demands.pop();
if (from_id == to_id) { if (from_id == to_id) {
/* Only one node with supply and demand left */ /* Only one node with supply and demand left */
if (demands.empty() && supplies.empty()) return; if (demands.empty() && supplies.empty()) return;
demands.push_back(to_id); demands.push(to_id);
continue; continue;
} }
@ -236,7 +236,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
scaler.SetDemands(job, from_id, to_id, demand_forw); scaler.SetDemands(job, from_id, to_id, demand_forw);
if (scaler.HasDemandLeft(job[to_id])) { if (scaler.HasDemandLeft(job[to_id])) {
demands.push_back(to_id); demands.push(to_id);
} else { } else {
num_demands--; num_demands--;
} }
@ -245,7 +245,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
} }
if (job[from_id].UndeliveredSupply() != 0) { if (job[from_id].UndeliveredSupply() != 0) {
supplies.push_back(from_id); supplies.push(from_id);
} else { } else {
num_supplies--; num_supplies--;
} }

@ -17,7 +17,7 @@
#include "../widget_type.h" #include "../widget_type.h"
#include "linkgraph_base.h" #include "linkgraph_base.h"
#include <map> #include <map>
#include <list> #include <vector>
/** /**
* Properties of a link between two stations. * Properties of a link between two stations.
@ -39,7 +39,7 @@ class LinkGraphOverlay {
public: public:
typedef std::map<StationID, LinkProperties> StationLinkMap; typedef std::map<StationID, LinkProperties> StationLinkMap;
typedef std::map<StationID, StationLinkMap> LinkMap; typedef std::map<StationID, StationLinkMap> LinkMap;
typedef std::list<std::pair<StationID, uint> > StationSupplyList; typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
static const uint8 LINK_COLOURS[]; static const uint8 LINK_COLOURS[];

@ -14,7 +14,7 @@
#include "../cargo_type.h" #include "../cargo_type.h"
#include "../vehicle_base.h" #include "../vehicle_base.h"
#include <list> #include <vector>
#include <map> #include <map>
#include <set> #include <set>
@ -79,7 +79,7 @@ protected:
bool operator<(const Hop &other) const; bool operator<(const Hop &other) const;
}; };
typedef std::list<RefitDesc> RefitList; typedef std::vector<RefitDesc> RefitList;
typedef std::map<CargoID, uint> CapacitiesMap; typedef std::map<CargoID, uint> CapacitiesMap;
typedef std::set<Hop> HopSet; typedef std::set<Hop> HopSet;

Loading…
Cancel
Save