Skip to content

Commit

Permalink
feat: add SiblingSubgraph::try_from_nodes_with_checker
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Sep 21, 2023
1 parent 981f4f9 commit 30ffddb
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ impl SiblingSubgraph {
pub fn try_from_nodes(
nodes: impl Into<Vec<Node>>,
hugr: &impl HugrView,
) -> Result<Self, InvalidSubgraph> {
let mut checker = ConvexChecker::new(hugr);
Self::try_from_nodes_with_checker(nodes, hugr, &mut checker)
}

/// Create a subgraph from a set of nodes.
///
/// Provide a [`ConvexChecker`] instance to avoid constructing one for
/// faster convexity check. If you do not have one, use
/// [`SiblingSubgraph::try_from_nodes`].
///
/// Refer to [`SiblingSubgraph::try_from_nodes`] for the full
/// documentation.
pub fn try_from_nodes_with_checker<'c, 'h: 'c, H: HugrView>(
nodes: impl Into<Vec<Node>>,
hugr: &'h H,
checker: &'c mut ConvexChecker<'h, H>,
) -> Result<Self, InvalidSubgraph> {
let nodes = nodes.into();
let nodes_set = nodes.iter().copied().collect::<HashSet<_>>();
Expand Down Expand Up @@ -251,7 +268,7 @@ impl SiblingSubgraph {
!nodes_set.contains(&in_n)
})
.collect_vec();
Self::try_new(inputs, outputs, hugr)
Self::try_new_with_checker(inputs, outputs, hugr, checker)
}

/// An iterator over the nodes in the subgraph.
Expand Down

0 comments on commit 30ffddb

Please sign in to comment.