pub struct Interner { /* private fields */ }Expand description
A structure’s identifier dictionary.
Interning is idempotent: the same string always yields the same identifier within one interner, and identifiers are issued in first-seen order, so two runs over the same file produce the same numbering.
Implementations§
Source§impl Interner
impl Interner
Sourcepub const DEFAULT_LIMIT: u32 = 1_000_000
pub const DEFAULT_LIMIT: u32 = 1_000_000
The largest number of local identifiers one structure may issue.
This is a guard, not a design target. Reaching it means input-generated identifiers rather than naming things.
Sourcepub fn retained_bytes(&self) -> usize
pub fn retained_bytes(&self) -> usize
Bytes retained by local arena, extent and lookup-table capacities.
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty dictionary over the canonical one.
Runs in O(1) time and creates no local-string allocation.
Sourcepub fn with_capacity(identifiers: usize) -> Self
pub fn with_capacity(identifiers: usize) -> Self
Creates a dictionary with room reserved for identifiers local strings.
The extent vector and hash table reserve capacity up front. The arena is left empty because the total byte length cannot be inferred from the number of identifiers.
Uses O(identifiers) reserved memory.
Sourcepub const fn with_limit(self, limit: u32) -> Self
pub const fn with_limit(self, limit: u32) -> Self
Sets the limit on local identifiers.
Runs in O(1) time and allocates no memory.
Sourcepub fn intern(&mut self, text: &str) -> Result<SymbolId, DictionaryFull>
pub fn intern(&mut self, text: &str) -> Result<SymbolId, DictionaryFull>
Returns the identifier for text, interning it if it is new.
Existing strings require no allocation. A new local string is copied exactly once into the arena and adds one extent and one table entry.
Expected running time is O(L), where L is text.len(). Insertion is
amortized over hash-table and arena growth.
§Errors
Returns DictionaryFull when the local dictionary has reached its
limit and text is not already in it.
Sourcepub fn get(&self, text: &str) -> Option<SymbolId>
pub fn get(&self, text: &str) -> Option<SymbolId>
Returns the identifier for text if it is already known, without
interning it.
This is what a selection uses: a name that no structure contains should resolve to nothing rather than growing the dictionary.
Expected running time is O(L), where L is text.len(). The operation
performs no allocation and does not mutate the dictionary.
Sourcepub fn resolve(&self, id: SymbolId) -> Option<&str>
pub fn resolve(&self, id: SymbolId) -> Option<&str>
Returns the string an identifier names.
Runs in O(1) time and allocates no memory. The returned slice borrows
either static canonical storage or this interner’s arena.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of local identifiers issued.
Runs in O(1) time and allocates no memory.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when no local identifier has been issued.
Runs in O(1) time and allocates no memory.
Sourcepub fn arena_len(&self) -> usize
pub fn arena_len(&self) -> usize
The bytes the local strings occupy.
Runs in O(1) time and allocates no memory.
Sourcepub fn iter(&self) -> impl Iterator<Item = (SymbolId, &str)>
pub fn iter(&self) -> impl Iterator<Item = (SymbolId, &str)>
Walks canonical and structure-local identifiers in stable id order.
This is the dictionary-side half of compiling glob predicates: pattern work is proportional to distinct identifiers and the atom loop remains integer membership. Iteration allocates nothing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interner
impl RefUnwindSafe for Interner
impl Send for Interner
impl Sync for Interner
impl Unpin for Interner
impl UnsafeUnpin for Interner
impl UnwindSafe for Interner
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