@@ -147,6 +147,21 @@ impl<N: HugrNode> OutputBoundaryMap<N> {
147
147
}
148
148
}
149
149
}
150
+
151
+ fn map_nodes < M : HugrNode > ( & self , node_map : impl Fn ( N ) -> M ) -> OutputBoundaryMap < M > {
152
+ match self {
153
+ OutputBoundaryMap :: ByIncoming ( map) => OutputBoundaryMap :: ByIncoming (
154
+ map. iter ( )
155
+ . map ( |( & ( node, port) , & val) | ( ( node_map ( node) , port) , val) )
156
+ . collect ( ) ,
157
+ ) ,
158
+ OutputBoundaryMap :: ByOutgoing ( map) => OutputBoundaryMap :: ByOutgoing (
159
+ map. iter ( )
160
+ . map ( |( & ( node, port) , & val) | ( ( node_map ( node) , port) , val) )
161
+ . collect ( ) ,
162
+ ) ,
163
+ }
164
+ }
150
165
}
151
166
152
167
impl < HostNode : HugrNode > SimpleReplacement < HostNode > {
@@ -392,6 +407,38 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
392
407
. chain ( outgoing_boundary)
393
408
. chain ( host_to_host_boundary)
394
409
}
410
+
411
+ /// Map the host nodes in `self` according to `node_map`.
412
+ ///
413
+ /// `node_map` must map nodes in the current HUGR of the subgraph to
414
+ /// its equivalent nodes in some `new_hugr`.
415
+ ///
416
+ /// This converts a replacement that acts on nodes of type `HostNode` to
417
+ /// a replacement that acts on `new_hugr`, with nodes of type `N`.
418
+ ///
419
+ /// This does not check convexity. It is up to the caller to ensure that
420
+ /// the mapped replacement obtained from this applies on a convex subgraph
421
+ /// of the new HUGR.
422
+ pub ( crate ) fn map_host_nodes < N : HugrNode > (
423
+ & self ,
424
+ node_map : impl Fn ( HostNode ) -> N ,
425
+ ) -> SimpleReplacement < N > {
426
+ let Self {
427
+ subgraph,
428
+ replacement,
429
+ nu_inp,
430
+ nu_out,
431
+ } = self ;
432
+ let nu_inp = nu_inp
433
+ . iter ( )
434
+ . map ( |( & repl_node_port, & ( host_node, host_port) ) | {
435
+ ( repl_node_port, ( node_map ( host_node) , host_port) )
436
+ } )
437
+ . collect ( ) ;
438
+ let nu_out = nu_out. map_nodes ( & node_map) ;
439
+ let subgraph = subgraph. map_nodes ( node_map) ;
440
+ SimpleReplacement :: new ( subgraph, replacement. clone ( ) , nu_inp, nu_out)
441
+ }
395
442
}
396
443
397
444
impl < HostNode : HugrNode > PatchVerification for SimpleReplacement < HostNode > {
0 commit comments