From 30ffddb9cff9ec423c3924d2e305a548e2ff2ae0 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Thu, 21 Sep 2023 13:48:36 +0100 Subject: [PATCH] feat: add `SiblingSubgraph::try_from_nodes_with_checker` --- src/hugr/views/sibling_subgraph.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/hugr/views/sibling_subgraph.rs b/src/hugr/views/sibling_subgraph.rs index fe6e9c0c5..941f783d2 100644 --- a/src/hugr/views/sibling_subgraph.rs +++ b/src/hugr/views/sibling_subgraph.rs @@ -220,6 +220,23 @@ impl SiblingSubgraph { pub fn try_from_nodes( nodes: impl Into>, hugr: &impl HugrView, + ) -> Result { + 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>, + hugr: &'h H, + checker: &'c mut ConvexChecker<'h, H>, ) -> Result { let nodes = nodes.into(); let nodes_set = nodes.iter().copied().collect::>(); @@ -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.