From 6c495707423cc7ce26c3027893dc812281b73053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Thu, 20 Apr 2023 15:56:28 +0800 Subject: [PATCH] [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. --- crates/chain/src/tx_graph.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index e16ae88d..a1ddbf87 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -603,11 +603,17 @@ impl TxGraph { impl TxGraph { /// Get all heights that are relevant to the graph. pub fn relevant_heights(&self) -> impl DoubleEndedIterator + '_ { - let mut visited = HashSet::new(); + let mut last_height = Option::::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`.