pub struct VarSymbolMapping { /* private fields */ }Expand description
Bidirectional mapping between VarId and SymbolId.
Uses SlotMap for stable VarId generation that supports deletion.
This provides:
- VarId → SymbolId: O(1) via SlotMap
- SymbolId → VarId: O(1) via SecondaryMap
§Usage
let mut mapping = VarSymbolMapping::new();
// Register a variable
let var_id = mapping.register(symbol_id);
// Lookup
let sym = mapping.to_symbol(var_id);
let var = mapping.to_var(symbol_id);
// Remove (for incremental updates)
mapping.remove(var_id);Implementations§
Source§impl VarSymbolMapping
impl VarSymbolMapping
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with pre-allocated capacity.
Sourcepub fn register(&mut self, symbol_id: SymbolId) -> VarId
pub fn register(&mut self, symbol_id: SymbolId) -> VarId
Register a named variable (with SymbolId) and return its VarId.
If the SymbolId is already registered, returns the existing VarId.
Sourcepub fn allocate(&mut self) -> VarId
pub fn allocate(&mut self) -> VarId
Allocate a fresh VarId for a local variable without a SymbolId.
Always creates a new unique VarId. No reverse lookup is registered.
Sourcepub fn remove(&mut self, var_id: VarId) -> Option<SymbolId>
pub fn remove(&mut self, var_id: VarId) -> Option<SymbolId>
Remove a variable by VarId.
Returns the associated SymbolId if it existed.
Sourcepub fn remove_by_symbol(&mut self, symbol_id: SymbolId) -> Option<VarId>
pub fn remove_by_symbol(&mut self, symbol_id: SymbolId) -> Option<VarId>
Remove a variable by SymbolId.
Returns the VarId if it existed.
Sourcepub fn to_symbol(&self, var_id: VarId) -> Option<SymbolId>
pub fn to_symbol(&self, var_id: VarId) -> Option<SymbolId>
Get the SymbolId for a VarId.
Returns None if the VarId doesn’t exist or has no associated SymbolId.
Sourcepub fn to_var(&self, symbol_id: SymbolId) -> Option<VarId>
pub fn to_var(&self, symbol_id: SymbolId) -> Option<VarId>
Get the VarId for a SymbolId.
Returns None if the SymbolId is not registered.
Sourcepub fn contains_symbol(&self, symbol_id: SymbolId) -> bool
pub fn contains_symbol(&self, symbol_id: SymbolId) -> bool
Check if a SymbolId is registered.
Sourcepub fn contains_var(&self, var_id: VarId) -> bool
pub fn contains_var(&self, var_id: VarId) -> bool
Check if a VarId is valid.
Trait Implementations§
Source§impl Clone for VarSymbolMapping
impl Clone for VarSymbolMapping
Source§fn clone(&self) -> VarSymbolMapping
fn clone(&self) -> VarSymbolMapping
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for VarSymbolMapping
impl Debug for VarSymbolMapping
Source§impl Default for VarSymbolMapping
impl Default for VarSymbolMapping
Source§fn default() -> VarSymbolMapping
fn default() -> VarSymbolMapping
Auto Trait Implementations§
impl Freeze for VarSymbolMapping
impl RefUnwindSafe for VarSymbolMapping
impl Send for VarSymbolMapping
impl Sync for VarSymbolMapping
impl Unpin for VarSymbolMapping
impl UnsafeUnpin for VarSymbolMapping
impl UnwindSafe for VarSymbolMapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more