Simplify selection of spare replacement bucket

This commit is contained in:
Cecylia Bocovich 2024-03-09 17:30:21 -05:00
parent 203b949d43
commit 6462027b7f
No known key found for this signature in database
GPG Key ID: 009DE379FD9B7B90
1 changed files with 9 additions and 12 deletions

View File

@ -564,18 +564,15 @@ impl BridgeAuth {
bucketnums.push(*bucketnum);
}
// Get the first spare and remove it from the spares set.
let mut spare = *self.bridge_table.spares.iter().next().unwrap();
// Check that the first spare in the list of spares is not the one to be replaced
if bucketnums.contains(&spare) {
// If it is, take the last spare instead
spare = *self.bridge_table.spares.iter().last().unwrap();
// If this is the same bucketnum, there is only one spare bucket with the bridge
// to be replaced in it, so don't replace it.
if bucketnums.contains(&spare) {
res = ReplaceSuccess::NotReplaced;
return res;
}
}
let Some(spare) = self
.bridge_table
.spares
.iter()
.find(|x| !bucketnums.contains(x))
.cloned()
else {
return ReplaceSuccess::NotReplaced;
};
self.bridge_table.spares.remove(&spare);
self.bridge_table.recycleable_keys.push(spare);
// Get the actual bridges from the spare bucket