[bdk_chain_redesign] Rm HashSet from TxGraph::relevant_heights

The `HashSet` was used for iterating without duplicate items. However,
since `anchors` is a `BTreeSet`, heights are in order. So a single
variable tracking last height will be sufficient.
This commit is contained in:
志宇 2023-04-20 15:56:28 +08:00
parent 1003fe2ee6
commit 6c49570742
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8

View File

@ -603,11 +603,17 @@ impl<A: Clone + Ord> TxGraph<A> {
impl<A: Anchor> TxGraph<A> {
/// Get all heights that are relevant to the graph.
pub fn relevant_heights(&self) -> impl DoubleEndedIterator<Item = u32> + '_ {
let mut visited = HashSet::new();
let mut last_height = Option::<u32>::None;
self.anchors
.iter()
.map(|(a, _)| a.anchor_block().height)
.filter(move |&h| visited.insert(h))
.filter(move |&height| {
let is_unique = Some(height) != last_height;
if is_unique {
last_height = Some(height);
}
is_unique
})
}
/// Get the position of the transaction in `chain` with tip `chain_tip`.