Skip to content

Commit

Permalink
get_index_of instead of get_full and docs on LinkTable explaini…
Browse files Browse the repository at this point in the history
…ng `K`.
  • Loading branch information
zrho committed Dec 17, 2024
1 parent 350c8fc commit 3824a05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions hugr-model/src/v0/scope/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ type FxIndexSet<K> = IndexSet<K, BuildHasherDefault<FxHasher>>;
/// Table for tracking links between ports.
///
/// Two ports are connected when they share the same link. Links are named and
/// scoped via isolated regions. The names of links must be unique within a
/// single isolated region. Links from one isolated region are not visible in
/// another. Links do not have a unique point of declaration.
/// scoped via isolated regions. Links from one isolated region are not visible
/// in another. Links do not have a unique point of declaration.
///
/// The link table keeps track of an association between a key of type `K` and
/// the link indices within each region. When resolving links from a text format,
/// `K` is the name of the link as a string slice. However the link table might
/// is also useful in other contexts where the key is not a string when constructing
/// a module from a different representation.
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions hugr-model/src/v0/scope/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ impl<'a> VarTable<'a> {
/// Panics if there are no open scopes.
pub fn resolve(&self, name: &'a str) -> Result<VarId, UnknownVarError<'a>> {
let scope = self.scopes.last().unwrap();
let (set_index, _) = self
let set_index = self
.vars
.get_full(&(scope.node, name))
.get_index_of(&(scope.node, name))
.ok_or(UnknownVarError(scope.node, name))?;
let var_index = (set_index - scope.var_stack) as u16;
Ok(VarId(scope.node, var_index))
Expand Down

0 comments on commit 3824a05

Please sign in to comment.