Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
swernli committed Sep 8, 2024
1 parent d248b11 commit 0a20cdf
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions compiler/qsc_circuit/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl Builder {
/// qubit ids are still reused for new allocations.
/// Measurements are tracked and deferred.
#[derive(Default)]
pub struct Remapper {
struct Remapper {
next_meas_id: usize,
next_qubit_id: usize,
next_qubit_hardware_id: HardwareId,
Expand All @@ -393,7 +393,7 @@ pub struct Remapper {
}

impl Remapper {
pub fn map(&mut self, qubit: usize) -> HardwareId {
fn map(&mut self, qubit: usize) -> HardwareId {
if let Some(mapped) = self.qubit_map.get(qubit) {
*mapped
} else {
Expand All @@ -404,55 +404,50 @@ impl Remapper {
}
}

pub fn m(&mut self, q: usize) -> usize {
fn m(&mut self, q: usize) -> usize {
let mapped_q = self.map(q);
let id = self.get_meas_id();
self.measurements.push((mapped_q, id));
id
}

pub fn mreset(&mut self, q: usize) -> usize {
fn mreset(&mut self, q: usize) -> usize {
let id = self.m(q);
self.reset(q);
id
}

pub fn reset(&mut self, q: usize) {
fn reset(&mut self, q: usize) {
self.qubit_map.remove(q);
}

pub fn qubit_allocate(&mut self) -> usize {
fn qubit_allocate(&mut self) -> usize {
let id = self.next_qubit_id;
self.next_qubit_id += 1;
let _ = self.map(id);
id
}

pub fn qubit_release(&mut self, _q: usize) {
fn qubit_release(&mut self, _q: usize) {
self.next_qubit_id -= 1;
}

pub fn swap(&mut self, q0: usize, q1: usize) {
fn swap(&mut self, q0: usize, q1: usize) {
let q0_mapped = self.map(q0);
let q1_mapped = self.map(q1);
self.qubit_map.insert(q0, q1_mapped);
self.qubit_map.insert(q1, q0_mapped);
}

pub fn measurements(&self) -> impl Iterator<Item = &(HardwareId, usize)> {
fn measurements(&self) -> impl Iterator<Item = &(HardwareId, usize)> {
self.measurements.iter()
}

#[must_use]
pub fn num_qubits(&self) -> usize {
fn num_qubits(&self) -> usize {
self.next_qubit_hardware_id.0
}

#[must_use]
pub fn num_measurements(&self) -> usize {
self.next_meas_id
}

#[must_use]
fn get_meas_id(&mut self) -> usize {
let id = self.next_meas_id;
Expand Down

0 comments on commit 0a20cdf

Please sign in to comment.