@@ -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 > {
@@ -361,41 +376,6 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
361
376
self . nu_inp . get ( & ( node, port) ) . copied ( ) . map ( Into :: into)
362
377
}
363
378
364
- /// Map the host nodes in `self` according to `node_map`.
365
- ///
366
- /// `node_map` must map nodes in the current HUGR of the subgraph to
367
- /// its equivalent nodes in some `new_hugr`.
368
- ///
369
- /// This converts a replacement that acts on nodes of type `HostNode` to
370
- /// a replacement that acts on `new_hugr`, with nodes of type `N`.
371
- ///
372
- /// This does not check convexity. It is up to the caller to ensure that
373
- /// the mapped replacement obtained from this applies on a convex subgraph
374
- /// of the new HUGR.
375
- pub ( crate ) fn map_host_nodes < N : HugrNode > (
376
- & self ,
377
- node_map : impl Fn ( HostNode ) -> N ,
378
- ) -> SimpleReplacement < N > {
379
- let Self {
380
- subgraph,
381
- replacement,
382
- nu_inp,
383
- nu_out,
384
- } = self ;
385
- let nu_inp = nu_inp
386
- . iter ( )
387
- . map ( |( & ( node, port) , & ( host_node, host_port) ) | {
388
- ( ( node, port) , ( node_map ( host_node) , host_port) )
389
- } )
390
- . collect ( ) ;
391
- let nu_out = nu_out
392
- . iter ( )
393
- . map ( |( & ( host_node, host_port) , & port) | ( ( node_map ( host_node) , host_port) , port) )
394
- . collect ( ) ;
395
- let subgraph = subgraph. map_nodes ( node_map) ;
396
- SimpleReplacement :: new ( subgraph, replacement. clone ( ) , nu_inp, nu_out)
397
- }
398
-
399
379
/// Get all edges that the replacement would add between `host` and
400
380
/// `self.replacement`.
401
381
///
@@ -427,6 +407,38 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
427
407
. chain ( outgoing_boundary)
428
408
. chain ( host_to_host_boundary)
429
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
+ }
430
442
}
431
443
432
444
impl < HostNode : HugrNode > PatchVerification for SimpleReplacement < HostNode > {
0 commit comments