From ae92c47cda59e279e2c552eed4f586b67b834b46 Mon Sep 17 00:00:00 2001 From: sjdilkes Date: Mon, 4 Dec 2023 20:17:29 +0000 Subject: [PATCH] clean up intersection code --- tket/src/Characterisation/Cycles.cpp | 19 +++++++++---------- .../Characterisation/FrameRandomisation.cpp | 2 -- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tket/src/Characterisation/Cycles.cpp b/tket/src/Characterisation/Cycles.cpp index 4205663284..20ba39c420 100644 --- a/tket/src/Characterisation/Cycles.cpp +++ b/tket/src/Characterisation/Cycles.cpp @@ -170,16 +170,15 @@ std::pair> CycleFinder::make_cycle( if (std::find( history_uids.begin(), history_uids.end(), not_present_uid) != history_uids.end()) { - // => the not present uid is in this cycle - // now we check the overlap - // - for (const UnitID& a : - this->cycle_history.history[candidate_cycle_key]) { - for (const UnitID& b : history_uids) { - if (a == b) { - not_mergeable_keys.insert(candidate_cycle_key); - } - } + std::vector intersection; + std::vector candidates = + cycle_history.history[candidate_cycle_key]; + std::set_intersection( + candidates.begin(), candidates.end(), history_uids.begin(), + history_uids.end(), std::back_inserter(intersection)); + if (!intersection.empty()) { + not_mergeable_keys.insert(candidate_cycle_key); + break; } } } diff --git a/tket/src/Characterisation/FrameRandomisation.cpp b/tket/src/Characterisation/FrameRandomisation.cpp index c2cc8fc0f2..eb899a9c16 100644 --- a/tket/src/Characterisation/FrameRandomisation.cpp +++ b/tket/src/Characterisation/FrameRandomisation.cpp @@ -45,8 +45,6 @@ std::string FrameRandomisation::to_string() const { // Wires Identity gates into each cycle edge. Identity gates then relabelled // with Ops from OpTypeSet to create instances of Frame Randomisation void add_noop_frames(std::vector& cycles, Circuit& circ) { - IndexMap imap = circ.index_map(); - std::map replacement_rewiring_edges; for (Cycle& full_cycle : cycles) { std::vector cycle = full_cycle.boundary_edges_;