Skip to content

Commit 54010b0

Browse files
Update consensus/proto_array/src/proto_array.rs
Co-authored-by: Michael Sproul <[email protected]>
1 parent cf3b776 commit 54010b0

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

consensus/proto_array/src/proto_array.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,19 +1060,10 @@ impl ProtoArray {
10601060

10611061
/// Returns all node indices that have zero children. May include unviable nodes.
10621062
fn nodes_without_children(&self) -> Vec<usize> {
1063-
let mut childs_of = HashMap::<_, Vec<_>>::new();
1064-
for (index, node) in self.nodes.iter().enumerate() {
1065-
// Create entry for this node
1066-
childs_of.entry(index).or_default();
1067-
// Add this node to the parent's child list if any
1068-
if let Some(parent_index) = node.parent {
1069-
childs_of.entry(parent_index).or_default().push(index);
1070-
}
1071-
}
1072-
childs_of
1073-
.into_iter()
1074-
.filter(|(_, childs)| childs.is_empty())
1075-
.map(|(index, _)| index)
1063+
self.nodes
1064+
.iter()
1065+
.enumerate()
1066+
.filter_map(|(i, node)| node.best_child.is_none().then_some(i))
10761067
.collect()
10771068
}
10781069
}

0 commit comments

Comments
 (0)