Minor fixes
This commit is contained in:
parent
6bff64f283
commit
45bb5756df
|
@ -344,7 +344,7 @@ impl BridgeAuth {
|
||||||
}
|
}
|
||||||
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
|
while self.bridge_table.unallocated_bridges.len() >= MAX_BRIDGES_PER_BUCKET {
|
||||||
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
||||||
for i in 0..MAX_BRIDGES_PER_BUCKET {
|
for i in 0..MAX_BRIDGES_PER_BUCKET {
|
||||||
bucket[i] = self.bridge_table.unallocated_bridges.pop().unwrap();
|
bucket[i] = self.bridge_table.unallocated_bridges.pop().unwrap();
|
||||||
}
|
}
|
||||||
self.add_openinv_bridges(bucket, bdb);
|
self.add_openinv_bridges(bucket, bdb);
|
||||||
|
@ -406,20 +406,19 @@ impl BridgeAuth {
|
||||||
&mut self,
|
&mut self,
|
||||||
bridge: &BridgeLine,
|
bridge: &BridgeLine,
|
||||||
available_bridge: Option<&BridgeLine>,
|
available_bridge: Option<&BridgeLine>,
|
||||||
bdb: &mut BridgeDb,
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut res: bool = false;
|
let mut res: bool = false;
|
||||||
let reachable_bridges = &self.bridge_table.reachable.clone();
|
let reachable_bridges = &self.bridge_table.reachable.clone();
|
||||||
if let Some(positions) = reachable_bridges.get(bridge) {
|
if let Some(positions) = reachable_bridges.get(bridge) {
|
||||||
if available_bridge.is_some() {
|
if let Some(replacement) = available_bridge {
|
||||||
for (bucketnum, offset) in positions.iter() {
|
for (bucketnum, offset) in positions.iter() {
|
||||||
assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge);
|
assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge);
|
||||||
self.bridge_table.buckets[*bucketnum as usize][*offset] =
|
self.bridge_table.buckets[*bucketnum as usize][*offset] =
|
||||||
*available_bridge.unwrap();
|
*replacement;
|
||||||
// Remove the bridge from the reachable bridges and add new bridge
|
// Remove the bridge from the reachable bridges and add new bridge
|
||||||
self.bridge_table
|
self.bridge_table
|
||||||
.reachable
|
.reachable
|
||||||
.insert(*available_bridge.unwrap(), positions.clone());
|
.insert(*replacement, positions.clone());
|
||||||
// Remove the bridge from the bucket
|
// Remove the bridge from the bucket
|
||||||
self.bridge_table.reachable.remove(bridge);
|
self.bridge_table.reachable.remove(bridge);
|
||||||
res = true
|
res = true
|
||||||
|
@ -442,7 +441,7 @@ impl BridgeAuth {
|
||||||
// Indicate the removed bucket as a recyclable bucket
|
// Indicate the removed bucket as a recyclable bucket
|
||||||
self.bridge_table.recyclable.insert(spare);
|
self.bridge_table.recyclable.insert(spare);
|
||||||
// Get the actual bridges from the spare bucket
|
// Get the actual bridges from the spare bucket
|
||||||
let spare_bucket = self.bridge_table.buckets[spare as usize].clone();
|
let spare_bucket = self.bridge_table.buckets[spare as usize];
|
||||||
let mut replacement: &BridgeLine = &BridgeLine::default();
|
let mut replacement: &BridgeLine = &BridgeLine::default();
|
||||||
// Make the first spare the replacement bridge, add the others to the set of
|
// Make the first spare the replacement bridge, add the others to the set of
|
||||||
// unallocated_bridges
|
// unallocated_bridges
|
||||||
|
|
|
@ -731,7 +731,7 @@ fn test_bridge_replace() {
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
th.ba
|
th.ba
|
||||||
.bridge_replace(replacement_bridge, Some(random_bridgeline), &mut th.bdb),
|
.bridge_replace(replacement_bridge, Some(random_bridgeline)),
|
||||||
"Bridge was not replaced with available bridge"
|
"Bridge was not replaced with available bridge"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -772,7 +772,7 @@ fn test_bridge_replace() {
|
||||||
"Unallocated bridge already marked as reachable"
|
"Unallocated bridge already marked as reachable"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
th.ba.bridge_replace(replacement_bridge, None, &mut th.bdb),
|
th.ba.bridge_replace(replacement_bridge, None),
|
||||||
"Bridge was not replaced with available bridge"
|
"Bridge was not replaced with available bridge"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -801,7 +801,7 @@ fn test_bridge_replace() {
|
||||||
"Unallocated bridges should have a length of 0"
|
"Unallocated bridges should have a length of 0"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
th.ba.bridge_replace(replacement_bridge, None, &mut th.bdb),
|
th.ba.bridge_replace(replacement_bridge, None),
|
||||||
"Bridge was not replaced with available spare bridge"
|
"Bridge was not replaced with available spare bridge"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -830,7 +830,7 @@ fn test_bridge_replace() {
|
||||||
"Unallocated bridges should have a length of 0"
|
"Unallocated bridges should have a length of 0"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
!th.ba.bridge_replace(replacement_bridge, None, &mut th.bdb),
|
!th.ba.bridge_replace(replacement_bridge, None),
|
||||||
"Bridge was somehow marked as replaced despite no replaceable bridges"
|
"Bridge was somehow marked as replaced despite no replaceable bridges"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
|
|
Loading…
Reference in New Issue