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