Skip to content

Commit

Permalink
Refactor: Rename interner set inner_set.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Aug 13, 2024
1 parent 5f04961 commit b8eeccc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct TargetInterner<T>
where
T: Hash + Clone + Eq,
{
gate_name_map: IndexSet<T, RandomState>,
inner_set: IndexSet<T, RandomState>,
}

impl<T> TargetInterner<T>
Expand All @@ -152,17 +152,17 @@ where
/// Creates a new interner instance.
pub fn new() -> Self {
Self {
gate_name_map: IndexSet::default(),
inner_set: IndexSet::default(),
}
}

/// Internalizes a gate name
pub fn intern_item(&mut self, item: T) -> u16 {
if let Some(index) = self.gate_name_map.get_index_of(&item) {
if let Some(index) = self.inner_set.get_index_of(&item) {
index as u16
} else {
let new_index = self.gate_name_map.len();
self.gate_name_map.insert(item);
let new_index = self.inner_set.len();
self.inner_set.insert(item);
new_index as u16
}
}
Expand All @@ -172,32 +172,32 @@ where
where
Q: ?Sized + Hash + Equivalent<T>,
{
self.gate_name_map.get_index_of(item).map(|x| x as u16)
self.inner_set.get_index_of(item).map(|x| x as u16)
}

/// Decodes the gate
pub fn intern_index(&self, gate_index: u16) -> Option<&T> {
self.gate_name_map.get_index(gate_index as usize)
self.inner_set.get_index(gate_index as usize)
}

pub fn reduce(&self) -> Vec<T> {
self.gate_name_map.iter().cloned().collect()
self.inner_set.iter().cloned().collect()
}

pub fn from_reduced<I>(reduced: I) -> Self
where
I: IntoIterator<Item = T>,
{
Self {
gate_name_map: IndexSet::from_iter(reduced),
inner_set: IndexSet::from_iter(reduced),
}
}

pub fn contains<Q>(&self, item: &Q) -> bool
where
Q: ?Sized + Hash + Equivalent<T>,
{
self.gate_name_map.contains(item)
self.inner_set.contains(item)
}
}

Expand Down

0 comments on commit b8eeccc

Please sign in to comment.