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}
145143template <typename T>
@@ -161,14 +159,8 @@ void CoordinatedPartitionState<T>::incrementMachineWeight(
161159template <typename T>
162160int 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}
173165template <typename T>
174166int CoordinatedPartitionState<T>::getMaxLoad() const {
@@ -177,18 +169,9 @@ int CoordinatedPartitionState<T>::getMaxLoad() const {
177169template <typename T>
178170int CoordinatedPartitionState<T>::getMachineWithMinWeight() const {
179171 std::lock_guard<std::mutex> lock (*machines_weight_edges_mutex);
180-
181- double MIN_LOAD = std::numeric_limits<double >::max ();
182- int machine_id = 0 ;
183- for (size_t i = 0 ; i < machines_weight_edges.size (); ++i) {
184- double loadi = machines_weight_edges[i];
185- if (loadi < MIN_LOAD) {
186- MIN_LOAD = loadi;
187- machine_id = i;
188- }
189- }
190-
191- return machine_id;
172+ return std::distance (machines_weight_edges.begin (),
173+ std::min_element (machines_weight_edges.begin (),
174+ machines_weight_edges.end ()));
192175}
193176template <typename T>
194177int CoordinatedPartitionState<T>::getMachineWithMinWeight(
0 commit comments