Further condense search for replacement spares

This commit is contained in:
Cecylia Bocovich 2024-03-09 20:06:27 -05:00
parent 762fef432f
commit 12deeddeb0
No known key found for this signature in database
GPG Key ID: 009DE379FD9B7B90
1 changed files with 2 additions and 6 deletions

View File

@ -552,16 +552,12 @@ impl BridgeAuth {
// - third dissolve a spare bucket to create more available bridges
let Some(replacement) = available_bridge.or_else(|| {
self.bridge_table.unallocated_bridges.pop().or_else(|| {
// First get the bucketnums for the replacement bridge in case it is a spare
let mut bucketnums: Vec<u32> = Vec::new();
for (bucketnum, _) in positions.iter() {
bucketnums.push(*bucketnum);
}
let Some(spare) = self
.bridge_table
.spares
.iter()
.find(|x| !bucketnums.contains(x))
// in case bridge is a spare, avoid replacing it with itself
.find(|x| !positions.iter().any(|(bucketnum, _)| &bucketnum == x))
.cloned()
else {
return None;