Skip to content

Commit 0dee6dd

Browse files
committed
Simplify code by using standard functions
1 parent 3074e9c commit 0dee6dd

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#pragma once
2424

25+
#include <algorithm>
2526
#include <memory>
2627
#include <mutex>
2728
#include <set>
@@ -136,10 +137,7 @@ void CoordinatedPartitionState<T>::incrementMachineLoad(
136137
const int m, shared<const Edge<T>> e) {
137138
std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
138139
machines_load_edges[m] = machines_load_edges[m] + 1;
139-
int new_value = machines_load_edges.at(m);
140-
if (new_value > MAX_LOAD) {
141-
MAX_LOAD = new_value;
142-
}
140+
MAX_LOAD = std::max(MAX_LOAD, machines_load_edges.at(m));
143141
partition_map[m]->addEdge(e);
144142
}
145143
template <typename T>
@@ -161,14 +159,8 @@ void CoordinatedPartitionState<T>::incrementMachineWeight(
161159
template <typename T>
162160
int CoordinatedPartitionState<T>::getMinLoad() const {
163161
std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
164-
int MIN_LOAD = std::numeric_limits<int>::max();
165-
for (const auto &machines_load_edges_it : machines_load_edges) {
166-
int loadi = machines_load_edges_it;
167-
if (loadi < MIN_LOAD) {
168-
MIN_LOAD = loadi;
169-
}
170-
}
171-
return MIN_LOAD;
162+
return *std::min_element(machines_load_edges.begin(),
163+
machines_load_edges.end());
172164
}
173165
template <typename T>
174166
int CoordinatedPartitionState<T>::getMaxLoad() const {

include/CXXGraph/Partitioning/HDRF.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,8 @@ void HDRF<T>::performStep(shared<const Edge<T>> e,
129129
fv = 1 + (1 - fv);
130130
}
131131
int load = state->getMachineLoad(m);
132-
double bal = (MAX_LOAD - load);
133-
bal /= (epsilon + MAX_LOAD - MIN_LOAD);
134-
if (bal < 0) {
135-
bal = 0;
136-
}
132+
const double bal =
133+
std::max(0.0, (MAX_LOAD - load) / (epsilon + MAX_LOAD - MIN_LOAD));
137134
double SCORE_m = fu + fv + lambda * bal;
138135
if (SCORE_m < 0) {
139136
std::cout << "ERRORE: SCORE_m<0" << std::endl;

0 commit comments

Comments
 (0)