Check more return values are as expected

By "Check" I mean I'm just unwrapping ones that should exist because I'm lazy
This commit is contained in:
Michael Bradley 2025-01-31 01:59:43 -05:00
parent ed1bd67b86
commit 70295da0ba
Signed by: MichaelBradley
SSH key fingerprint: SHA256:cj/YZ5VT+QOKncqSkx+ibKTIn0Obg7OIzwzl9BL8EO8

View file

@ -78,12 +78,14 @@ impl<D: Hash + Eq + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync>
if smaller_child < self.data[i] { if smaller_child < self.data[i] {
// Swap parent with child // Swap parent with child
self.data[smaller_child_index] = self.data[i].clone(); self.data[smaller_child_index] = self.data[i].clone();
self.indices.insert( self.indices
self.data[smaller_child_index].clone().data(), .insert(
smaller_child_index, self.data[smaller_child_index].clone().data(),
); smaller_child_index,
)
.unwrap();
self.data[i] = smaller_child.clone(); self.data[i] = smaller_child.clone();
self.indices.insert(smaller_child.data(), i); self.indices.insert(smaller_child.data(), i).unwrap();
// Repeat process with child // Repeat process with child
self.sift_down(smaller_child_index) self.sift_down(smaller_child_index)
@ -113,7 +115,7 @@ impl<D: Hash + Eq + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync>
} else { } else {
self.data.pop().unwrap(); self.data.pop().unwrap();
} }
self.indices.remove(pair.get_data()); self.indices.remove(pair.get_data()).unwrap();
Some(pair) Some(pair)
} }
} }
@ -162,7 +164,9 @@ impl<D: Hash + Eq + Clone + Send + Sync, P: PartialOrd + Clone + Send + Sync> In
} }
} else { } else {
let final_index = self.data.len(); let final_index = self.data.len();
self.indices.insert(data.clone(), final_index); if let Some(_) = self.indices.insert(data.clone(), final_index) {
panic!("Item was not consistently hashed")
}
self.data.push(Pair::new(data, priority)); self.data.push(Pair::new(data, priority));
self.sift_up(final_index).unwrap(); self.sift_up(final_index).unwrap();
} }