Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SiblingSubgraph::try_from_nodes_with_checker #547

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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