@@ -177,7 +177,6 @@ bool PolicyAcross::validate(std::vector<LocalityEntry> const& solutionSet,
177177// Choose new servers from "least utilized" alsoServers and append the new servers to results
178178// fromserverse are the servers that have already been chosen and
179179// that should be excluded from being selected as replicas.
180- // FIXME: Simplify this function, such as removing unnecessary printf
181180// fromServers are the servers that must have;
182181// alsoServers are the servers you can choose.
183182bool PolicyAcross::selectReplicas (Reference<LocalitySet>& fromServers,
@@ -197,8 +196,7 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
197196 for (auto & alsoServer : alsoServers) {
198197 auto value = fromServers->getValueViaGroupKey (alsoServer, groupIndexKey);
199198 if (value.present ()) {
200- auto lowerBound = std::lower_bound (_usedValues.begin (), _usedValues.end (), value.get ());
201- if ((lowerBound == _usedValues.end ()) || (*lowerBound != value.get ())) {
199+ if (!_usedValues.contains (value.get ())) {
202200 // _selected is a set of processes that have the same indexKey and indexValue (value)
203201 _selected = fromServers->restrict (indexKey, value.get ());
204202 if (_selected->size ()) {
@@ -213,7 +211,7 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
213211 }
214212 if (count >= _count)
215213 break ;
216- _usedValues.insert (lowerBound, value.get ());
214+ _usedValues.insert (value.get ());
217215 }
218216 }
219217 }
@@ -258,15 +256,14 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
258256 auto & entry = mutableArray[recordIndex];
259257 auto value = fromServers->getValueViaGroupKey (entry, groupIndexKey);
260258 if (value.present ()) {
261- auto lowerBound = std::lower_bound (_usedValues.begin (), _usedValues.end (), value.get ());
262- if ((lowerBound == _usedValues.end ()) || (*lowerBound != value.get ())) {
259+ if (!_usedValues.contains (value.get ())) {
263260 _selected = fromServers->restrict (indexKey, value.get ());
264261 if (_selected->size ()) {
265262 if (_policy->selectReplicas (_selected, emptyEntryArray, results)) {
266263 count++;
267264 if (count >= _count)
268265 break ;
269- _usedValues.insert (lowerBound, value.get ());
266+ _usedValues.insert (value.get ());
270267 }
271268 }
272269 }
0 commit comments