Skip to content

Commit

Permalink
[bdk_chain_redesign] Rm HashSet from TxGraph::relevant_heights
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evanlinjin committed Apr 20, 2023
1 parent 1003fe2 commit 6c49570
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 6c49570

Please sign in to comment.