@@ -548,33 +548,23 @@ impl WireTracker {
548
548
let mut value_wires = Vec :: new ( ) ;
549
549
while !qubit_args. is_empty ( ) || !bit_args. is_empty ( ) {
550
550
// Check candidate wires that only contain the elements we need, in the right order.
551
+ //
552
+ // We may have leftover arguments at the end, which we'll try to
553
+ // get from another wire.
551
554
let filter_candidate_wire = |w : Wire | {
552
- let mut wire_qubits = self . wires [ & w] . qubits . iter ( ) . peekable ( ) ;
553
- let mut wire_bits = self . wires [ & w] . bits . iter ( ) . peekable ( ) ;
554
- let mut q_args_iter = qubit_args. iter ( ) . map ( |( id, _) | id) ;
555
- let mut b_args_iter = bit_args. iter ( ) . map ( |( id, _) | id) ;
556
-
557
- // Check that each argument appears as either a qubit or a bit
558
- // in the wire, in the right order.
559
- //
560
- // We may have leftover arguments at the end, which we'll try to
561
- // get from another wire.
562
- while wire_qubits. peek ( ) . is_some ( ) && wire_bits. peek ( ) . is_some ( ) {
563
- if let Some ( qb) = wire_qubits. next ( ) {
564
- match q_args_iter. next ( ) {
565
- Some ( arg) if qb == arg => continue ,
566
- _ => return false ,
567
- } ;
568
- }
569
- if let Some ( bit) = wire_bits. next ( ) {
570
- match b_args_iter. next ( ) {
571
- Some ( arg) if bit == arg => continue ,
572
- _ => return false ,
573
- } ;
574
- }
575
- return false ;
576
- }
577
- true
555
+ let wire_data = & self . wires [ & w] ;
556
+ let same_qubits = itertools:: equal (
557
+ wire_data. qubits . iter ( ) ,
558
+ qubit_args
559
+ . iter ( )
560
+ . map ( |( id, _) | id)
561
+ . take ( wire_data. num_qubits ( ) ) ,
562
+ ) ;
563
+ let same_bits = itertools:: equal (
564
+ wire_data. bits . iter ( ) ,
565
+ bit_args. iter ( ) . map ( |( id, _) | id) . take ( wire_data. num_bits ( ) ) ,
566
+ ) ;
567
+ same_qubits && same_bits
578
568
} ;
579
569
580
570
let qubit_candidates = qubit_args
0 commit comments