Codechange: Remove min/max functions in favour of STL variants (#8502)
This commit is contained in:
@@ -45,7 +45,7 @@ public:
|
||||
*/
|
||||
inline void SetDemandPerNode(uint num_demands)
|
||||
{
|
||||
this->demand_per_node = max(this->supply_sum / num_demands, 1U);
|
||||
this->demand_per_node = std::max(this->supply_sum / num_demands, 1U);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
*/
|
||||
inline uint EffectiveSupply(const Node &from, const Node &to)
|
||||
{
|
||||
return max(from.Supply() * max(1U, to.Supply()) * this->mod_size / 100 / this->demand_per_node, 1U);
|
||||
return std::max(from.Supply() * std::max(1U, to.Supply()) * this->mod_size / 100 / this->demand_per_node, 1U);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +134,7 @@ void SymmetricScaler::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to_id
|
||||
uint undelivered = job[to_id].UndeliveredSupply();
|
||||
if (demand_back > undelivered) {
|
||||
demand_back = undelivered;
|
||||
demand_forw = max(1U, demand_back * 100 / this->mod_size);
|
||||
demand_forw = std::max(1U, demand_back * 100 / this->mod_size);
|
||||
}
|
||||
this->Scaler::SetDemands(job, to_id, from_id, demand_back);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
|
||||
demand_forw = 1;
|
||||
}
|
||||
|
||||
demand_forw = min(demand_forw, job[from_id].UndeliveredSupply());
|
||||
demand_forw = std::min(demand_forw, job[from_id].UndeliveredSupply());
|
||||
|
||||
scaler.SetDemands(job, from_id, to_id, demand_forw);
|
||||
|
||||
|
@@ -71,7 +71,7 @@ void LinkGraph::Compress()
|
||||
for (NodeID node2 = 0; node2 < this->Size(); ++node2) {
|
||||
BaseEdge &edge = this->edges[node1][node2];
|
||||
if (edge.capacity > 0) {
|
||||
edge.capacity = max(1U, edge.capacity / 2);
|
||||
edge.capacity = std::max(1U, edge.capacity / 2);
|
||||
edge.usage /= 2;
|
||||
}
|
||||
}
|
||||
@@ -163,8 +163,7 @@ NodeID LinkGraph::AddNode(const Station *st)
|
||||
this->nodes.emplace_back();
|
||||
/* Avoid reducing the height of the matrix as that is expensive and we
|
||||
* most likely will increase it again later which is again expensive. */
|
||||
this->edges.Resize(new_node + 1U,
|
||||
max(new_node + 1U, this->edges.Height()));
|
||||
this->edges.Resize(new_node + 1U, std::max(new_node + 1U, this->edges.Height()));
|
||||
|
||||
this->nodes[new_node].Init(st->xy, st->index,
|
||||
HasBit(good.status, GoodsEntry::GES_ACCEPTANCE));
|
||||
@@ -266,8 +265,8 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, EdgeUpdateMode mode)
|
||||
this->edge.capacity += capacity;
|
||||
this->edge.usage += usage;
|
||||
} else if (mode & EUM_REFRESH) {
|
||||
this->edge.capacity = max(this->edge.capacity, capacity);
|
||||
this->edge.usage = max(this->edge.usage, usage);
|
||||
this->edge.capacity = std::max(this->edge.capacity, capacity);
|
||||
this->edge.usage = std::max(this->edge.usage, usage);
|
||||
}
|
||||
if (mode & EUM_UNRESTRICTED) this->edge.last_unrestricted_update = _date;
|
||||
if (mode & EUM_RESTRICTED) this->edge.last_restricted_update = _date;
|
||||
|
@@ -113,7 +113,7 @@ public:
|
||||
* Get the date of the last update to any part of the edge's capacity.
|
||||
* @return Last update.
|
||||
*/
|
||||
Date LastUpdate() const { return max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
|
||||
Date LastUpdate() const { return std::max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
*/
|
||||
inline static uint Scale(uint val, uint target_age, uint orig_age)
|
||||
{
|
||||
return val > 0 ? max(1U, val * target_age / orig_age) : 0;
|
||||
return val > 0 ? std::max(1U, val * target_age / orig_age) : 0;
|
||||
}
|
||||
|
||||
/** Bare constructor, only for save/load. */
|
||||
|
@@ -224,7 +224,7 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
|
||||
{
|
||||
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
|
||||
if (cargo.capacity == 0 ||
|
||||
max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) {
|
||||
std::max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < std::max(new_usg, new_plan) * 32 / (new_cap + 1)) {
|
||||
cargo.capacity = new_cap;
|
||||
cargo.usage = new_usg;
|
||||
cargo.planned = new_plan;
|
||||
@@ -272,7 +272,7 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
|
||||
*/
|
||||
void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
|
||||
{
|
||||
uint usage_or_plan = min(cargo.capacity * 2 + 1, max(cargo.usage, cargo.planned));
|
||||
uint usage_or_plan = std::min(cargo.capacity * 2 + 1, std::max(cargo.usage, cargo.planned));
|
||||
int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)];
|
||||
int dash = cargo.shared ? this->scale * 4 : 0;
|
||||
|
||||
@@ -302,7 +302,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
|
||||
Point pt = this->GetStationMiddle(st);
|
||||
if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
|
||||
|
||||
uint r = this->scale * 2 + this->scale * 2 * min(200, i->second) / 200;
|
||||
uint r = this->scale * 2 + this->scale * 2 * std::min(200U, i->second) / 200;
|
||||
|
||||
LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
|
||||
_colour_gradient[st->owner != OWNER_NONE ?
|
||||
|
@@ -223,8 +223,8 @@ void LinkGraphJob::NodeAnnotation::Init(uint supply)
|
||||
*/
|
||||
void Path::Fork(Path *base, uint cap, int free_cap, uint dist)
|
||||
{
|
||||
this->capacity = min(base->capacity, cap);
|
||||
this->free_capacity = min(base->free_capacity, free_cap);
|
||||
this->capacity = std::min(base->capacity, cap);
|
||||
this->free_capacity = std::min(base->free_capacity, free_cap);
|
||||
this->distance = base->distance + dist;
|
||||
assert(this->distance > 0);
|
||||
if (this->parent != base) {
|
||||
@@ -250,7 +250,7 @@ uint Path::AddFlow(uint new_flow, LinkGraphJob &job, uint max_saturation)
|
||||
if (max_saturation != UINT_MAX) {
|
||||
uint usable_cap = edge.Capacity() * max_saturation / 100;
|
||||
if (usable_cap > edge.Flow()) {
|
||||
new_flow = min(new_flow, usable_cap - edge.Flow());
|
||||
new_flow = std::min(new_flow, usable_cap - edge.Flow());
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@@ -392,7 +392,7 @@ public:
|
||||
*/
|
||||
inline static int GetCapacityRatio(int free, uint total)
|
||||
{
|
||||
return Clamp(free, PATH_CAP_MIN_FREE, PATH_CAP_MAX_FREE) * PATH_CAP_MULTIPLIER / max(total, 1U);
|
||||
return Clamp(free, PATH_CAP_MIN_FREE, PATH_CAP_MAX_FREE) * PATH_CAP_MULTIPLIER / std::max(total, 1U);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -235,7 +235,7 @@ bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint cap,
|
||||
bool CapacityAnnotation::IsBetter(const CapacityAnnotation *base, uint cap,
|
||||
int free_cap, uint dist) const
|
||||
{
|
||||
int min_cap = Path::GetCapacityRatio(min(base->free_capacity, free_cap), min(base->capacity, cap));
|
||||
int min_cap = Path::GetCapacityRatio(std::min(base->free_capacity, free_cap), std::min(base->capacity, cap));
|
||||
int this_cap = this->GetCapacityRatio();
|
||||
if (min_cap == this_cap) {
|
||||
/* If the capacities are the same and the other path isn't disconnected
|
||||
@@ -354,7 +354,7 @@ uint MCF1stPass::FindCycleFlow(const PathVector &path, const Path *cycle_begin)
|
||||
uint flow = UINT_MAX;
|
||||
const Path *cycle_end = cycle_begin;
|
||||
do {
|
||||
flow = min(flow, cycle_begin->GetFlow());
|
||||
flow = std::min(flow, cycle_begin->GetFlow());
|
||||
cycle_begin = path[cycle_begin->GetNode()];
|
||||
} while (cycle_begin != cycle_end);
|
||||
return flow;
|
||||
|
Reference in New Issue
Block a user